Gammu internals  1.38.0
bluetooth.c
Go to the documentation of this file.
1 /* (c) 2003-2004 by Marcin Wiacek and Marcel Holtmann and others */
2 
3 #include "../../gsmstate.h"
4 
5 #ifdef GSM_ENABLE_BLUETOOTHDEVICE
6 #ifndef DJGPP
7 
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <fcntl.h>
11 #include <errno.h>
12 #include <string.h>
13 
14 #include "../../gsmcomon.h"
15 #include "../devfunc.h"
16 #include "bluetooth.h"
17 
18 #include "../../../helper/string.h"
19 
20 #ifdef BLUEZ_FOUND
21 # include "bluez.h"
22 #endif
23 #ifdef BSD_BLUE_FOUND
24 # include "blue_bsd.h"
25 #endif
26 #ifdef OSX_BLUE_FOUND
27 # include "blue_osx.h"
28 #endif
29 #ifdef WIN32
30 # include "blue_w32.h"
31 #endif
32 
33 GSM_Error bluetooth_findrfchannel(GSM_StateMachine *s)
34 {
35  GSM_Error error;
36  char *device;
37  char *channel;
38  int channel_id = 0;
39 
40  /* Temporary string */
41  device = strdup(s->CurrentConfig->Device);
42  if (device == NULL) {
43  return ERR_MOREMEMORY;
44  }
45 
46  /* Does the string contain channel information? */
47  /* Default device on *NIX is /dev/.., so we need to ignore it here as well. */
48  channel = strchr(device, '/');
49  if ((device[0] == '/' || channel == NULL) &&
50  strncasecmp(s->CurrentConfig->Connection, "bluerf", 6) != 0) {
51  free(device);
52  device=NULL;
53 #ifdef BLUETOOTH_RF_SEARCHING
54  return bluetooth_findchannel(s);
55 #else
56  smprintf(s, "WARNING: Channel searching not implemented on your platform!\n");
57  smprintf(s, "Please user bluerf* connection or define channel in configuration\n");
58  smprintf(s, "You can specify channel by adding it after phone address separated by slash\n");
59  smprintf(s, "For example: 11:22:33:44:55:66/12\n");
61 #endif
62  }
63 
64  /* Default channel settings */
65  switch (s->ConnectionType) {
66  case GCT_BLUEAT:
67  channel_id = 1;
68  break;
69  case GCT_BLUEOBEX:
70  channel_id = 9;
71  break;
72  case GCT_BLUEGNAPBUS:
73  channel_id = 14;
74  break;
75  case GCT_BLUEFBUS2: /* fixme */
76  case GCT_BLUEPHONET:
77  channel_id = 15;
78  break;
79  case GCT_BLUES60:
80  channel_id = 18;
81  break;
82  default:
83  channel_id = 0;
84  break;
85  }
86 
87  /* Parse channel from configuration */
88  if (channel != NULL) {
89  /* Zero terminate our string */
90  *channel = 0;
91  /* Grab channel number */
92  channel++;
93  channel_id = atoi(channel);
94  } else {
95  /* Notify user about hard wired default */
96  smprintf(s, "Using hard coded bluetooth channel %d.\n",
97  channel_id);
98  }
99 
100  /* Check for zero */
101  if (channel_id == 0) {
102  smprintf(s, "Please configure bluetooth channel!\n");
103  error = ERR_SPECIFYCHANNEL;
104  goto done;
105  }
106 
107 
108  /* Connect to phone */
109  error = bluetooth_connect(s, channel_id, device);
110  if (error == ERR_NONE) goto done;
111 
112  /* Hack for Nokia phones, they moved channel from 14 to 15, so
113  * we want to try both.
114  *
115  * Older Series 40 (eg. 8910 and 6310) use channel 14
116  * Newer Series 40 (eg. 6230 and 6310i) use channel 15
117  * */
118  if (((s->ConnectionType == GCT_BLUEPHONET) ||
119  (s->ConnectionType == GCT_BLUEFBUS2)) &&
120  (channel_id == 15)) {
121  channel_id = 14;
122  error = bluetooth_connect(s, channel_id, device);
123  }
124 
125 done:
126  free(device);
127  device=NULL;
128  return error;
129 }
130 
131 #ifndef OSX_BLUE_FOUND
132 int bluetooth_read(GSM_StateMachine *s, void *buf, size_t nbytes)
133 {
134  return socket_read(s, buf, nbytes, s->Device.Data.BlueTooth.hPhone);
135 }
136 
137 int bluetooth_write(GSM_StateMachine *s, const void *buf, size_t nbytes)
138 {
139  return socket_write(s, buf, nbytes, s->Device.Data.BlueTooth.hPhone);
140 }
141 
143 {
144  return socket_close(s, s->Device.Data.BlueTooth.hPhone);
145 }
146 #endif
147 
148 GSM_Device_Functions BlueToothDevice = {
149  bluetooth_findrfchannel,
151  NONEFUNCTION,
152  NONEFUNCTION,
153  NONEFUNCTION,
156 };
157 
158 #endif
159 #endif
160 
161 /* How should editor hadle tabs in this file? Add editor commands here.
162  * vim: noexpandtab sw=8 ts=8 sts=8:
163  */
GSM_Config * CurrentConfig
Definition: gsmstate.h:1415
union GSM_Device::@0 Data
GSM_ConnectionType ConnectionType
Definition: gsmstate.h:1402
int bluetooth_write(GSM_StateMachine *s, const void *buf, size_t nbytes)
#define NONEFUNCTION
Definition: gsmcomon.h:12
GSM_Error
Definition: gammu-error.h:23
GSM_Error bluetooth_connect(GSM_StateMachine *s, int port, char *device)
GSM_Error bluetooth_close(GSM_StateMachine *s)
GSM_Error bluetooth_findchannel(GSM_StateMachine *s)
GSM_Device Device
Definition: gsmstate.h:1429
int bluetooth_read(GSM_StateMachine *s, void *buf, size_t nbytes)
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261