From e73424f36dbfec59656986fdd2880bbd693f6379 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 15:27:29 +0000 Subject: [PATCH] tweak types git-svn-id: http://svn.openzap.org/svn/openzap/trunk@53 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/sangoma_tdm_api.h | 290 ++++++++++----------- 1 file changed, 145 insertions(+), 145 deletions(-) diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index 24f601c2de..a58caf5d8d 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -33,34 +33,34 @@ /* 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 */ /* 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 */ #if 0 -struct iphdr { - -#if defined(__LITTLE_ENDIAN_BITFIELD) - unsigned ihl:4, - version:4; -#elif defined (__BIG_ENDIAN_BITFIELD) - unsigned version:4, - ihl:4; -#else -# error "unknown byteorder!" -#endif - unsigned tos:8; - unsigned tot_len:16; - unsigned id:16; - unsigned frag_off:16; - __u8 ttl; - __u8 protocol; - __u16 check; - __u32 saddr; - __u32 daddr; - /*The options start here. */ -}; +struct iphdr { + +#if defined(__LITTLE_ENDIAN_BITFIELD) + unsigned ihl:4, + version:4; +#elif defined (__BIG_ENDIAN_BITFIELD) + unsigned version:4, + ihl:4; +#else +# error "unknown byteorder!" +#endif + unsigned tos:8; + unsigned tot_len:16; + unsigned id:16; + unsigned frag_off:16; + __u8 ttl; + __u8 protocol; + __u16 check; + __u32 saddr; + __u32 daddr; + /*The options start here. */ +}; #endif /* #if 0 */ #define __inline__ __inline @@ -90,7 +90,7 @@ struct iphdr { /* what should the returns from this function be?? */ /* I dont think they are currently consistant between windows and *nix */ #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 */ /* 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 } #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); } @@ -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 */ /* 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 */ -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 */ - /* the memcpy's on windows and still maintain api compat with nix */ - int rx_len=0; -#if defined(__WINDOWS__) - static RX_DATA_STRUCT rx_data; - api_header_t *pri; - 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; +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 */ + /* the memcpy's on windows and still maintain api compat with nix */ + int rx_len=0; +#if defined(__WINDOWS__) + static RX_DATA_STRUCT rx_data; + api_header_t *pri; + 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; DWORD ln; - - if(hdrlen != sizeof(wp_tdm_api_rx_hdr_t)){ - return -1; - } - + + if(hdrlen != sizeof(wp_tdm_api_rx_hdr_t)){ + return -1; + } + if(!DeviceIoControl( fd, IoctlReadCommand, @@ -316,111 +316,111 @@ static __inline__ int tdmv_api_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen sizeof(RX_DATA_STRUCT), (LPDWORD)(&ln), (LPOVERLAPPED)NULL - )){ - return -1; - } - - pri = &rx_data.api_header; - tdm_api_rx_hdr = (wp_tdm_api_rx_hdr_t*)rx_data.data; - - user_buf->wp_tdm_api_event_type = pri->operation_status; - - switch(pri->operation_status) - { - case SANG_STATUS_RX_DATA_AVAILABLE: - if(pri->data_length > datalen){ - break; - } - memcpy(databuf, rx_data.data, pri->data_length); - rx_len = pri->data_length; - break; - - default: - break; - } - -#else - struct msghdr msg; - struct iovec iov[2]; - - memset(&msg,0,sizeof(struct msghdr)); - - iov[0].iov_len=hdrlen; - iov[0].iov_base=hdrbuf; - - iov[1].iov_len=datalen; - iov[1].iov_base=databuf; - - msg.msg_iovlen=2; - msg.msg_iov=iov; - - rx_len = read(fd,&msg,datalen+hdrlen); - - if (rx_len <= sizeof(wp_tdm_api_rx_hdr_t)){ - return -EINVAL; - } - - rx_len-=sizeof(wp_tdm_api_rx_hdr_t); -#endif - return rx_len; -} + )){ + return -1; + } -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 */ - /* the memcpy's on windows and still maintain api compat with nix */ - int bsent = 0; -#if defined(__WINDOWS__) - static TX_DATA_STRUCT local_tx_data; - api_header_t *pri; - DWORD ln; - - /* Are these really not needed or used??? What about for nix?? */ - (void)hdrbuf; - (void)hdrlen; - - pri = &local_tx_data.api_header; - - pri->data_length = datalen; - memcpy(local_tx_data.data, databuf, pri->data_length); - - if(!DeviceIoControl( - fd, - IoctlWriteCommand, - (LPVOID)&local_tx_data, - (ULONG)sizeof(TX_DATA_STRUCT), - (LPVOID)&local_tx_data, - sizeof(TX_DATA_STRUCT), - (LPDWORD)(&ln), - (LPOVERLAPPED)NULL - )){ - return -1; - } - - if (local_tx_data.api_header.operation_status == SANG_STATUS_SUCCESS) { - bsent = datalen; - } -#else - struct msghdr msg; - struct iovec iov[2]; - - memset(&msg,0,sizeof(struct msghdr)); - - iov[0].iov_len=hdrlen; - iov[0].iov_base=hdrbuf; - - iov[1].iov_len=datalen; - iov[1].iov_base=databuf; - - msg.msg_iovlen=2; - msg.msg_iov=iov; - - bsent = write(fd,&msg,datalen+hdrlen); - if (bsent > 0){ - bsent-=sizeof(wp_tdm_api_tx_hdr_t); - } -#endif - return bsent; -} + pri = &rx_data.api_header; + tdm_api_rx_hdr = (wp_tdm_api_rx_hdr_t*)rx_data.data; + + user_buf->wp_tdm_api_event_type = pri->operation_status; + + switch(pri->operation_status) + { + case SANG_STATUS_RX_DATA_AVAILABLE: + if(pri->data_length > datalen){ + break; + } + memcpy(databuf, rx_data.data, pri->data_length); + rx_len = pri->data_length; + break; + + default: + break; + } + +#else + struct msghdr msg; + struct iovec iov[2]; + + memset(&msg,0,sizeof(struct msghdr)); + + iov[0].iov_len=hdrlen; + iov[0].iov_base=hdrbuf; + + iov[1].iov_len=datalen; + iov[1].iov_base=databuf; + + msg.msg_iovlen=2; + msg.msg_iov=iov; + + rx_len = read(fd,&msg,datalen+hdrlen); + + if (rx_len <= sizeof(wp_tdm_api_rx_hdr_t)){ + return -EINVAL; + } + + rx_len-=sizeof(wp_tdm_api_rx_hdr_t); +#endif + return rx_len; +} + +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 */ + /* the memcpy's on windows and still maintain api compat with nix */ + int bsent = 0; +#if defined(__WINDOWS__) + static TX_DATA_STRUCT local_tx_data; + api_header_t *pri; + DWORD ln; + + /* Are these really not needed or used??? What about for nix?? */ + (void)hdrbuf; + (void)hdrlen; + + pri = &local_tx_data.api_header; + + pri->data_length = datalen; + memcpy(local_tx_data.data, databuf, pri->data_length); + + if(!DeviceIoControl( + fd, + IoctlWriteCommand, + (LPVOID)&local_tx_data, + (ULONG)sizeof(TX_DATA_STRUCT), + (LPVOID)&local_tx_data, + sizeof(TX_DATA_STRUCT), + (LPDWORD)(&ln), + (LPOVERLAPPED)NULL + )){ + return -1; + } + + if (local_tx_data.api_header.operation_status == SANG_STATUS_SUCCESS) { + bsent = datalen; + } +#else + struct msghdr msg; + struct iovec iov[2]; + + memset(&msg,0,sizeof(struct msghdr)); + + iov[0].iov_len=hdrlen; + iov[0].iov_base=hdrbuf; + + iov[1].iov_len=datalen; + iov[1].iov_base=databuf; + + msg.msg_iovlen=2; + msg.msg_iov=iov; + + bsent = write(fd,&msg,datalen+hdrlen); + if (bsent > 0){ + bsent-=sizeof(wp_tdm_api_tx_hdr_t); + } +#endif + return bsent; +} #endif /* _SANGOMA_TDM_API_H */