提交 e73424f3 authored 作者: Michael Jerris's avatar Michael Jerris

tweak types

git-svn-id: http://svn.openzap.org/svn/openzap/trunk@53 a93c3328-9c30-0410-af19-c9cd2b2d52af
上级 8f340bf0
...@@ -33,34 +33,34 @@ ...@@ -33,34 +33,34 @@
/* sang_api.h(74) : warning C4201: nonstandard extension used : nameless struct/union */ /* sang_api.h(74) : warning C4201: nonstandard extension used : nameless struct/union */
/* wanpipe_defines.h(219) : warning C4214: nonstandard extension used : bit field types other than int */ /* wanpipe_defines.h(219) : warning C4214: nonstandard extension used : bit field types other than int */
/* wanpipe_defines.h(220) : warning C4214: nonstandard extension used : bit field types other than int */ /* wanpipe_defines.h(220) : warning C4214: nonstandard extension used : bit field types other than int */
/* this will break for any compilers that are strict ansi or strict c99 */ /* this will break for any compilers that are strict ansi or strict c99 */
/* The following definition for that struct should resolve this warning and work for 32 and 64 bit */ /* The following definition for that struct should resolve this warning and work for 32 and 64 bit */
#if 0 #if 0
struct iphdr { struct iphdr {
#if defined(__LITTLE_ENDIAN_BITFIELD) #if defined(__LITTLE_ENDIAN_BITFIELD)
unsigned ihl:4, unsigned ihl:4,
version:4; version:4;
#elif defined (__BIG_ENDIAN_BITFIELD) #elif defined (__BIG_ENDIAN_BITFIELD)
unsigned version:4, unsigned version:4,
ihl:4; ihl:4;
#else #else
# error "unknown byteorder!" # error "unknown byteorder!"
#endif #endif
unsigned tos:8; unsigned tos:8;
unsigned tot_len:16; unsigned tot_len:16;
unsigned id:16; unsigned id:16;
unsigned frag_off:16; unsigned frag_off:16;
__u8 ttl; __u8 ttl;
__u8 protocol; __u8 protocol;
__u16 check; __u16 check;
__u32 saddr; __u32 saddr;
__u32 daddr; __u32 daddr;
/*The options start here. */ /*The options start here. */
}; };
#endif /* #if 0 */ #endif /* #if 0 */
#define __inline__ __inline #define __inline__ __inline
...@@ -90,7 +90,7 @@ struct iphdr { ...@@ -90,7 +90,7 @@ struct iphdr {
/* what should the returns from this function be?? */ /* what should the returns from this function be?? */
/* I dont think they are currently consistant between windows and *nix */ /* I dont think they are currently consistant between windows and *nix */
#ifdef __WINDOWS__ #ifdef __WINDOWS__
static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd)
{ {
/* can we make the structure passed for this on nix and windows the same */ /* can we make the structure passed for this on nix and windows the same */
/* so we don't have to do the extra 2 memcpy's on windows for this ? */ /* so we don't have to do the extra 2 memcpy's on windows for this ? */
...@@ -129,7 +129,7 @@ static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api ...@@ -129,7 +129,7 @@ static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api
} }
#else #else
static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_cmd_t *tdm_api_cmd) static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd)
{ {
return ioctl(fd, SIOC_WANPIPE_TDM_API, tdm_api_cmd); return ioctl(fd, SIOC_WANPIPE_TDM_API, tdm_api_cmd);
} }
...@@ -291,22 +291,22 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) ...@@ -291,22 +291,22 @@ static __inline__ int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags)
/* we need some what to select if we are reading regular tdm msgs or events */ /* we need some what to select if we are reading regular tdm msgs or events */
/* need to either have 2 functions, 1 for events, 1 for regural read, or a flag on this function to choose */ /* need to either have 2 functions, 1 for events, 1 for regural read, or a flag on this function to choose */
/* 2 functions preferred. Need implementation for the event function for both nix and windows that is threadsafe */ /* 2 functions preferred. Need implementation for the event function for both nix and windows that is threadsafe */
static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, int datalen) static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, int datalen)
{ {
/* What do we need to do here to avoid having to do all */ /* What do we need to do here to avoid having to do all */
/* the memcpy's on windows and still maintain api compat with nix */ /* the memcpy's on windows and still maintain api compat with nix */
int rx_len=0; int rx_len=0;
#if defined(__WINDOWS__) #if defined(__WINDOWS__)
static RX_DATA_STRUCT rx_data; static RX_DATA_STRUCT rx_data;
api_header_t *pri; api_header_t *pri;
wp_tdm_api_rx_hdr_t *tdm_api_rx_hdr; wp_tdm_api_rx_hdr_t *tdm_api_rx_hdr;
wp_tdm_api_rx_hdr_t *user_buf = (wp_tdm_api_rx_hdr_t*)hdrbuf; wp_tdm_api_rx_hdr_t *user_buf = (wp_tdm_api_rx_hdr_t*)hdrbuf;
DWORD ln; DWORD ln;
if(hdrlen != sizeof(wp_tdm_api_rx_hdr_t)){ if(hdrlen != sizeof(wp_tdm_api_rx_hdr_t)){
return -1; return -1;
} }
if(!DeviceIoControl( if(!DeviceIoControl(
fd, fd,
IoctlReadCommand, IoctlReadCommand,
...@@ -316,111 +316,111 @@ static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen ...@@ -316,111 +316,111 @@ static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen
sizeof(RX_DATA_STRUCT), sizeof(RX_DATA_STRUCT),
(LPDWORD)(&ln), (LPDWORD)(&ln),
(LPOVERLAPPED)NULL (LPOVERLAPPED)NULL
)){ )){
return -1; return -1;
} }
pri = &rx_data.api_header; pri = &rx_data.api_header;
tdm_api_rx_hdr = (wp_tdm_api_rx_hdr_t*)rx_data.data; tdm_api_rx_hdr = (wp_tdm_api_rx_hdr_t*)rx_data.data;
user_buf->wp_tdm_api_event_type = pri->operation_status; user_buf->wp_tdm_api_event_type = pri->operation_status;
switch(pri->operation_status) switch(pri->operation_status)
{ {
case SANG_STATUS_RX_DATA_AVAILABLE: case SANG_STATUS_RX_DATA_AVAILABLE:
if(pri->data_length > datalen){ if(pri->data_length > datalen){
break; break;
} }
memcpy(databuf, rx_data.data, pri->data_length); memcpy(databuf, rx_data.data, pri->data_length);
rx_len = pri->data_length; rx_len = pri->data_length;
break; break;
default: default:
break; break;
} }
#else #else
struct msghdr msg; struct msghdr msg;
struct iovec iov[2]; struct iovec iov[2];
memset(&msg,0,sizeof(struct msghdr)); memset(&msg,0,sizeof(struct msghdr));
iov[0].iov_len=hdrlen; iov[0].iov_len=hdrlen;
iov[0].iov_base=hdrbuf; iov[0].iov_base=hdrbuf;
iov[1].iov_len=datalen; iov[1].iov_len=datalen;
iov[1].iov_base=databuf; iov[1].iov_base=databuf;
msg.msg_iovlen=2; msg.msg_iovlen=2;
msg.msg_iov=iov; msg.msg_iov=iov;
rx_len = read(fd,&msg,datalen+hdrlen); rx_len = read(fd,&msg,datalen+hdrlen);
if (rx_len <= sizeof(wp_tdm_api_rx_hdr_t)){ if (rx_len <= sizeof(wp_tdm_api_rx_hdr_t)){
return -EINVAL; return -EINVAL;
} }
rx_len-=sizeof(wp_tdm_api_rx_hdr_t); rx_len-=sizeof(wp_tdm_api_rx_hdr_t);
#endif #endif
return rx_len; return rx_len;
} }
static __inline__ int tdmv_api_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, unsigned short datalen) static __inline__ int tdmv_api_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, unsigned short datalen)
{ {
/* What do we need to do here to avoid having to do all */ /* What do we need to do here to avoid having to do all */
/* the memcpy's on windows and still maintain api compat with nix */ /* the memcpy's on windows and still maintain api compat with nix */
int bsent = 0; int bsent = 0;
#if defined(__WINDOWS__) #if defined(__WINDOWS__)
static TX_DATA_STRUCT local_tx_data; static TX_DATA_STRUCT local_tx_data;
api_header_t *pri; api_header_t *pri;
DWORD ln; DWORD ln;
/* Are these really not needed or used??? What about for nix?? */ /* Are these really not needed or used??? What about for nix?? */
(void)hdrbuf; (void)hdrbuf;
(void)hdrlen; (void)hdrlen;
pri = &local_tx_data.api_header; pri = &local_tx_data.api_header;
pri->data_length = datalen; pri->data_length = datalen;
memcpy(local_tx_data.data, databuf, pri->data_length); memcpy(local_tx_data.data, databuf, pri->data_length);
if(!DeviceIoControl( if(!DeviceIoControl(
fd, fd,
IoctlWriteCommand, IoctlWriteCommand,
(LPVOID)&local_tx_data, (LPVOID)&local_tx_data,
(ULONG)sizeof(TX_DATA_STRUCT), (ULONG)sizeof(TX_DATA_STRUCT),
(LPVOID)&local_tx_data, (LPVOID)&local_tx_data,
sizeof(TX_DATA_STRUCT), sizeof(TX_DATA_STRUCT),
(LPDWORD)(&ln), (LPDWORD)(&ln),
(LPOVERLAPPED)NULL (LPOVERLAPPED)NULL
)){ )){
return -1; return -1;
} }
if (local_tx_data.api_header.operation_status == SANG_STATUS_SUCCESS) { if (local_tx_data.api_header.operation_status == SANG_STATUS_SUCCESS) {
bsent = datalen; bsent = datalen;
} }
#else #else
struct msghdr msg; struct msghdr msg;
struct iovec iov[2]; struct iovec iov[2];
memset(&msg,0,sizeof(struct msghdr)); memset(&msg,0,sizeof(struct msghdr));
iov[0].iov_len=hdrlen; iov[0].iov_len=hdrlen;
iov[0].iov_base=hdrbuf; iov[0].iov_base=hdrbuf;
iov[1].iov_len=datalen; iov[1].iov_len=datalen;
iov[1].iov_base=databuf; iov[1].iov_base=databuf;
msg.msg_iovlen=2; msg.msg_iovlen=2;
msg.msg_iov=iov; msg.msg_iov=iov;
bsent = write(fd,&msg,datalen+hdrlen); bsent = write(fd,&msg,datalen+hdrlen);
if (bsent > 0){ if (bsent > 0){
bsent-=sizeof(wp_tdm_api_tx_hdr_t); bsent-=sizeof(wp_tdm_api_tx_hdr_t);
} }
#endif #endif
return bsent; return bsent;
} }
#endif /* _SANGOMA_TDM_API_H */ #endif /* _SANGOMA_TDM_API_H */
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论