2 /* Have to include wsock32.lib library to MS VC6 project to compile it */
4 #include "../../gsmstate.h"
6 #ifdef GSM_ENABLE_IRDADEVICE
16 # include <sys/time.h>
17 # include <sys/poll.h>
18 # include <sys/socket.h>
19 # include <sys/ioctl.h>
25 #include "../../gsmcomon.h"
26 #include "../devfunc.h"
29 static bool irda_discover_device(GSM_StateMachine
*state
)
31 GSM_Device_IrdaData
*d
= &state
->Device
.Data
.Irda
;
32 struct irda_device_list
*list
;
38 bool founddevice
= false;
44 WSAStartup(MAKEWORD(1,1), &wsaData
);
47 fd
= socket(AF_IRDA
, SOCK_STREAM
, 0);
49 /* maximally 10 devices in discover */
50 len
= sizeof(struct irda_device_list
) + sizeof(struct irda_device_info
) * 10;
52 list
= (struct irda_device_list
*)buf
;
54 /* Trying to find device during 2 seconds */
56 GSM_GetCurrentDateTime (&Date
);
58 while (sec
==Date
.Second
) {
62 if (getsockopt(fd
, SOL_IRLMP
, IRLMP_ENUMDEVICES
, buf
, &s
) == 0) {
63 for (i
= 0; i
< (int)list
->numDevice
; i
++) {
64 dbgprintf("Irda: found device \"%s\" (address %x) - ",list
->Device
[i
].irdaDeviceName
,list
->Device
[i
].irdaDeviceID
);
65 if (strcmp(GetModelData(NULL
,NULL
,list
->Device
[i
].irdaDeviceName
)->number
,"") != 0) {
68 if (state
->CurrentConfig
->Model
[0]==0) strcpy(state
->Phone
.Data
.Model
,GetModelData(NULL
,NULL
,list
->Device
[i
].irdaDeviceName
)->number
);
69 state
->Phone
.Data
.ModelInfo
= GetModelData(NULL
,state
->Phone
.Data
.Model
,NULL
);
72 dbgprintf("correct\n");
74 for(index
=0; index
<= 3; index
++)
75 d
->peer
.irdaDeviceID
[index
] = list
->Device
[i
].irdaDeviceID
[index
];
77 d
->peer
.irdaDeviceID
= list
->Device
[i
].irdaDeviceID
;
84 if (founddevice
) break;
86 GSM_GetCurrentDateTime(&Date
);
88 if (founddevice
) break;
96 static GSM_Error
irda_open (GSM_StateMachine
*s
)
99 int Enable9WireMode
= 1;
101 GSM_Device_IrdaData
*d
= &s
->Device
.Data
.Irda
;
105 if (s
->ConnectionType
== GCT_IRDAAT
) return GE_SOURCENOTAVAILABLE
;
108 /* discover the devices */
109 if (irda_discover_device(s
)==false) return GE_TIMEOUT
;
112 fd
= socket(AF_IRDA
, SOCK_STREAM
, 0);
114 d
->peer
.irdaAddressFamily
= AF_IRDA
;
116 d
->peer
.sir_lsap_sel
= LSAP_ANY
;
118 switch (s
->ConnectionType
) {
120 strcpy(d
->peer
.irdaServiceName
, "IrDA:IrCOMM");
123 if (setsockopt(fd
, SOL_IRLMP
, IRLMP_9WIRE_MODE
, (const char *) &Enable9WireMode
,
124 sizeof(int))==SOCKET_ERROR
) return GE_UNKNOWN
;
128 strcpy(d
->peer
.irdaServiceName
, "Nokia:PhoNet");
131 /* IrDA:OBEX not supported by N3650 */
132 // strcpy(d->peer.irdaServiceName, "IrDA:OBEX");
134 strcpy(d
->peer
.irdaServiceName
, "OBEX");
136 /* Alternative server is "OBEX:IrXfer" */
142 /* Connect to service */
143 if (connect(fd
, (struct sockaddr
*)&d
->peer
, sizeof(d
->peer
))) {
144 dbgprintf("Can't connect to service %s\n",d
->peer
.irdaServiceName
);
146 return GE_NOTSUPPORTED
;
154 static int irda_read(GSM_StateMachine
*s
, void *buf
, size_t nbytes
)
156 return socket_read(s
, buf
, nbytes
, s
->Device
.Data
.Irda
.hPhone
);
160 static int irda_write(GSM_StateMachine
*s
, unsigned char *buf
, size_t nbytes
)
162 static int irda_write(GSM_StateMachine
*s
, void *buf
, size_t nbytes
)
165 return socket_write(s
, buf
, nbytes
, s
->Device
.Data
.Irda
.hPhone
);
168 static GSM_Error
irda_close(GSM_StateMachine
*s
)
170 return socket_close(s
, s
->Device
.Data
.Irda
.hPhone
);
173 GSM_Device_Functions IrdaDevice
= {
186 /* How should editor hadle tabs in this file? Add editor commands here.
187 * vim: noexpandtab sw=8 ts=8 sts=8: