19 # include <winsock2.h> 25 # include <sys/socket.h> 26 # include <sys/stat.h> 30 #include "../gsmstate.h" 32 #ifdef GSM_ENABLE_BLUETOOTHDEVICE 33 #ifdef BLUETOOTH_RF_SEARCHING 39 if (strstr(name,
"Nokia PC Suite") != NULL)
return 1;
43 if (strstr(name,
"pys60_remote") != NULL)
return 1;
48 if (strstr(name,
"Nokia OBEX PC Suite Services") != NULL) {
55 if (strstr(name,
"OBEX File Transfer") != NULL || strstr(name,
"OBEX file transfer") != NULL) {
63 if (strstr(name,
"IrMC Sync") != NULL || strstr(name,
"OBEX Synchronisation")) {
71 if (strstr(name,
"OBEX Object Push") != NULL) {
80 if (strstr(name,
"PSE") != NULL) {
87 if (strstr(name,
"PBAP") != NULL) {
95 if (strstr(name,
"OPP") != NULL) {
102 if (strstr(name,
"OBEX") != NULL)
return 1;
107 if (strstr(name,
"Dial-Up Networking") != NULL)
return 2;
109 if (strstr(name,
"Serial Port 1") != NULL)
return 3;
110 if (strstr(name,
"Serial Port") != NULL)
return 2;
112 if (strstr(name,
"Dial-up networking Gateway") != NULL)
return 3;
113 if (strstr(name,
"Serial port") != NULL)
return 2;
115 if (strstr(name,
"Dial-up Networking") != NULL)
return 3;
116 if (strstr(name,
"Dial-Up Networking Gateway") != NULL)
return 3;
117 if (strstr(name,
"Dialup Networking") != NULL)
return 3;
118 if (strstr(name,
"Serial Server") != NULL)
return 3;
120 if (strstr(name,
"SerialPort1") != NULL)
return 3;
121 if (strstr(name,
"SerialPort") != NULL)
return 2;
124 if (strstr(name,
"MyPhoneExplorer") != NULL)
return 1;
126 if (strstr(name,
"COM1") != NULL)
return 3;
127 if (strstr(name,
"COM") != NULL)
return 1;
136 #if defined (GSM_ENABLE_BLUETOOTHDEVICE) || defined (GSM_ENABLE_IRDADEVICE) 140 #define MSG_DONTWAIT 0 147 struct timeval timer;
150 FD_SET(hPhone, &readfds);
155 if (select(hPhone + 1, &readfds, NULL, NULL, &timer) > 0) {
156 result = recv(hPhone, buf, nbytes, MSG_DONTWAIT);
158 if (result < 0 && errno != EINTR) {
173 ret = send(hPhone, buf, nbytes - actual, 0);
175 if (actual != nbytes) {
178 if (errno != EINTR) {
187 }
while (actual < nbytes);
205 #define max_buf_len 128 206 #define lock_path "/var/lock/LCK.." 211 #if !defined(WIN32) && !defined(DJGPP) 214 char *lock_file = NULL;
226 aux = strrchr(port,
'/');
236 memset(buffer, 0,
sizeof(buffer));
237 lock_file = calloc(len + 1, 1);
239 smprintf(s,
"Out of memory error while locking device\n");
246 strcat(lock_file, aux);
250 if ((fd = open(lock_file, O_RDONLY)) >= 0) {
251 n = read(fd, buf,
sizeof(buf) - 1);
255 if (n == 4 && 4 ==
sizeof(
int) &&
257 isdigit((
int)buf[0]) &&
258 isdigit((
int)buf[1]) &&
259 isdigit((
int)buf[2]) &&
263 lseek(fd, 0, SEEK_SET);
266 n = read(fd, &pid,
sizeof(
int));
268 smprintf(s,
"Reading lock for second time failed\n");
275 sscanf(buf,
"%d", &pid);
281 if (pid > 0 && kill((pid_t)pid, 0) < 0 && errno == ESRCH) {
282 smprintf(s,
"Lockfile %s is stale. Overriding it..\n", lock_file);
283 if (unlink(lock_file) != 0) {
284 smprintf(s,
"Overriding failed, please check the permissions\n");
285 smprintf(s,
"Cannot lock device\n");
290 smprintf(s,
"Device already locked by PID %d.\n", pid);
297 fd = open(lock_file, O_CREAT | O_EXCL | O_WRONLY, 0644);
299 if (errno == EEXIST) {
300 smprintf(s,
"Device seems to be locked by unknown process\n");
302 }
else if (errno == EACCES) {
303 smprintf(s,
"Please check permission on lock directory\n");
305 }
else if (errno == ENOENT) {
306 smprintf(s,
"Cannot create lockfile %s. Please check for existence of path\n", lock_file);
309 smprintf(s,
"Unknown error with creating lockfile %s\n", lock_file);
314 sprintf(buffer,
"%10ld gammu\n", (
long)getpid());
315 wrotebytes = write(fd, buffer, strlen(buffer));
318 if (wrotebytes != strlen(buffer)) {
322 *lock_name = lock_file;
325 smprintf(s,
"Unable to read lockfile %s.\n", lock_file);
326 smprintf(s,
"Please check for reason and remove the lockfile by hand.\n");
327 smprintf(s,
"Cannot lock device\n");
346 #if !defined(WIN32) && !defined(DJGPP) 351 if (lock_file == NULL || *lock_file == NULL) {
352 smprintf(s,
"Cannot unlock device\n");
355 err = unlink(*lock_file);
369 switch (atoi(buffer)) {
372 case 110 :
return 110;
373 case 134 :
return 134;
374 case 150 :
return 150;
375 case 200 :
return 200;
376 case 300 :
return 300;
377 case 600 :
return 600;
378 case 1200 :
return 1200;
379 case 1800 :
return 1800;
380 case 2400 :
return 2400;
381 case 3600 :
return 3600;
382 case 4800 :
return 4800;
383 case 7200 :
return 7200;
384 case 9600 :
return 9600;
385 case 14400 :
return 14400;
386 case 19200 :
return 19200;
387 case 28800 :
return 28800;
388 case 38400 :
return 38400;
389 case 57600 :
return 57600;
390 case 115200 :
return 115200;
391 case 230400 :
return 230400;
392 case 460800 :
return 460800;
393 case 614400 :
return 614400;
394 case 921600 :
return 921600;
395 case 1228800 :
return 1228800;
396 case 2457600 :
return 2457600;
397 case 3000000 :
return 3000000;
398 case 6000000 :
return 6000000;
GSM_Config * CurrentConfig
GSM_ConnectionType ConnectionType
int FindSerialSpeed(const char *buffer)
gboolean unlock_device(GSM_StateMachine *s, char **lock_file)
void GSM_OSErrorInfo(GSM_StateMachine *s, const char *description)
int smprintf(GSM_StateMachine *s, const char *format,...)
GSM_Error lock_device(GSM_StateMachine *s, const char *port, char **lock_name)