mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-15 13:58:32 +00:00
update1
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@216 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
1 parent
6bf627a3d4
commit
b23a8ae4d6
13 files changed
+631
-213
No files matched your search
@@ -87,124 +87,6 @@ struct iphdr {
|
||||
|
||||
#define FNAME_LEN 50
|
||||
|
||||
/* 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_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 ? */
|
||||
wan_udp_hdr_t wan_udp;
|
||||
DWORD ln;
|
||||
unsigned char id = 0;
|
||||
|
||||
wan_udp.wan_udphdr_request_reply = 0x01;
|
||||
wan_udp.wan_udphdr_id = id;
|
||||
wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
|
||||
|
||||
wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL;
|
||||
wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t);
|
||||
|
||||
memcpy( wan_udp.wan_udphdr_data, (void*)tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t));
|
||||
|
||||
if (DeviceIoControl(
|
||||
fd,
|
||||
IoctlManagementCommand,
|
||||
(LPVOID)&wan_udp,
|
||||
sizeof(wan_udp_hdr_t),
|
||||
(LPVOID)&wan_udp,
|
||||
sizeof(wan_udp_hdr_t),
|
||||
(LPDWORD)(&ln),
|
||||
(LPOVERLAPPED)NULL
|
||||
) == FALSE){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK){
|
||||
return 2;
|
||||
}
|
||||
|
||||
memcpy( (void*)tdm_api_cmd, wan_udp.wan_udphdr_data, sizeof(wanpipe_tdm_api_cmd_t));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
||||
void __inline__ tdmv_api_close_socket(sng_fd_t *sp)
|
||||
{
|
||||
if ( *sp != WP_INVALID_SOCKET){
|
||||
#if defined(__WINDOWS__)
|
||||
CloseHandle(*sp);
|
||||
#else
|
||||
close(*sp);
|
||||
#endif
|
||||
*sp = WP_INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
|
||||
static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan)
|
||||
{
|
||||
char fname[FNAME_LEN];
|
||||
sng_fd_t fd = WP_INVALID_SOCKET;
|
||||
#if defined(__WINDOWS__)
|
||||
DWORD ln;
|
||||
wan_udp_hdr_t wan_udp;
|
||||
|
||||
/* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */
|
||||
/* Subtract 1 from 'chan'. */
|
||||
_snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1);
|
||||
|
||||
fd = CreateFile( fname,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
(LPSECURITY_ATTRIBUTES)NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,
|
||||
(HANDLE)NULL
|
||||
);
|
||||
|
||||
/* make sure that we are the only ones who have this chan open */
|
||||
/* is this a threadsafe way to make sure that we are ok and will */
|
||||
/* never return a valid handle to more than one thread for the same channel? */
|
||||
|
||||
wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER;
|
||||
wan_udp.wan_udphdr_data_len = 0;
|
||||
|
||||
DeviceIoControl(
|
||||
fd,
|
||||
IoctlManagementCommand,
|
||||
(LPVOID)&wan_udp,
|
||||
sizeof(wan_udp_hdr_t),
|
||||
(LPVOID)&wan_udp,
|
||||
sizeof(wan_udp_hdr_t),
|
||||
(LPDWORD)(&ln),
|
||||
(LPOVERLAPPED)NULL
|
||||
);
|
||||
|
||||
if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){
|
||||
/* somone already has this channel, or somthing else is not right. */
|
||||
tdmv_api_close_socket(&fd);
|
||||
}
|
||||
|
||||
#else
|
||||
/* Does this fail if another thread already has this chan open? */
|
||||
/* if not, we need to add some code to make sure it does */
|
||||
snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan);
|
||||
|
||||
fd = open(fname, O_RDWR);
|
||||
|
||||
if (fd < 0) {
|
||||
fd = WP_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
#endif
|
||||
return fd;
|
||||
}
|
||||
|
||||
#if defined(__WINDOWS__)
|
||||
/* This might be broken on windows, as POLL_EVENT_TELEPHONY seems to be commented out in sang_api.h.. it should be added to POLLPRI */
|
||||
|
||||
Reference in new issue
Block a user