-rw-r--r-- | gammu/emb/common/device/bluetoth/bluez.c | 29 | ||||
-rw-r--r-- | gammu/emb/common/device/devfunc.c | 12 | ||||
-rw-r--r-- | gammu/emb/common/device/irda/irda.c | 8 | ||||
-rw-r--r-- | gammu/emb/common/device/irda/irda_unx.h | 2 | ||||
-rw-r--r-- | gammu/emb/common/device/serial/ser_djg.c | 10 | ||||
-rw-r--r-- | gammu/emb/common/device/serial/ser_unx.c | 38 | ||||
-rw-r--r-- | gammu/emb/common/device/serial/ser_w32.c | 6 |
7 files changed, 79 insertions, 26 deletions
diff --git a/gammu/emb/common/device/bluetoth/bluez.c b/gammu/emb/common/device/bluetoth/bluez.c index 8a4807e..e7e8adf 100644 --- a/gammu/emb/common/device/bluetoth/bluez.c +++ b/gammu/emb/common/device/bluetoth/bluez.c | |||
@@ -1,207 +1,216 @@ | |||
1 | /* Based on work by Marcel Holtmann and other authors of Bluez */ | 1 | /* Based on some work from Bluez (www.bluez.org) |
2 | * (C) 2000-2001 Qualcomm Incorporated | ||
3 | * (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com> | ||
4 | * (C) 2002-2004 Marcel Holtmann <marcel@holtmann.org> | ||
5 | * GNU GPL version 2 | ||
6 | */ | ||
7 | /* based on some Marcel Holtmann work from Gnokii (www.gnokii.org) | ||
8 | * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot | ||
9 | * GNU GPL version 2 or later | ||
10 | */ | ||
2 | 11 | ||
3 | #include "../../gsmstate.h" | 12 | #include "../../gsmstate.h" |
4 | 13 | ||
5 | #ifdef GSM_ENABLE_BLUETOOTHDEVICE | 14 | #ifdef GSM_ENABLE_BLUETOOTHDEVICE |
6 | #ifdef GSM_ENABLE_BLUEZ | 15 | #ifdef GSM_ENABLE_BLUEZ |
7 | 16 | ||
8 | #include <stdlib.h> | 17 | #include <stdlib.h> |
9 | #include <stdio.h> | 18 | #include <stdio.h> |
10 | #include <fcntl.h> | 19 | #include <fcntl.h> |
11 | #include <errno.h> | 20 | #include <errno.h> |
12 | #include <string.h> | 21 | #include <string.h> |
13 | #include <sys/socket.h> | 22 | #include <sys/socket.h> |
14 | #include <sys/time.h> | 23 | #include <sys/time.h> |
15 | #include <unistd.h> | 24 | #include <unistd.h> |
16 | #include <bluetooth/bluetooth.h> | 25 | #include <bluetooth/bluetooth.h> |
17 | #include <bluetooth/rfcomm.h> | 26 | #include <bluetooth/rfcomm.h> |
18 | #include <bluetooth/sdp.h> | 27 | #include <bluetooth/sdp.h> |
19 | #include <bluetooth/sdp_lib.h> | 28 | #include <bluetooth/sdp_lib.h> |
20 | 29 | ||
21 | #include "../../gsmcomon.h" | 30 | #include "../../gsmcomon.h" |
22 | #include "../devfunc.h" | 31 | #include "../devfunc.h" |
23 | #include "bluetoth.h" | 32 | #include "bluetoth.h" |
24 | 33 | ||
25 | GSM_Error bluetooth_connect(GSM_StateMachine *s, int port, char *device) | 34 | GSM_Error bluetooth_connect(GSM_StateMachine *s, int port, char *device) |
26 | { | 35 | { |
27 | GSM_Device_BlueToothData *d = &s->Device.Data.BlueTooth; | 36 | GSM_Device_BlueToothData *d = &s->Device.Data.BlueTooth; |
28 | struct sockaddr_rc laddr, raddr; | 37 | struct sockaddr_rc laddr, raddr; |
29 | bdaddr_t bdaddr; | 38 | bdaddr_t bdaddr; |
30 | int fd; | 39 | int fd; |
31 | 40 | ||
32 | smprintf(s, "Connecting to RF channel %i\n",port); | 41 | smprintf(s, "Connecting to RF channel %i\n",port); |
33 | 42 | ||
34 | fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); | 43 | fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); |
35 | if (fd < 0) { | 44 | if (fd < 0) { |
36 | dbgprintf("Can't create socket\n"); | 45 | dbgprintf("Can't create socket\n"); |
37 | return ERR_DEVICENODRIVER; | 46 | return ERR_DEVICENODRIVER; |
38 | } | 47 | } |
39 | 48 | ||
40 | bacpy(&laddr.rc_bdaddr, BDADDR_ANY); | 49 | bacpy(&laddr.rc_bdaddr, BDADDR_ANY); |
41 | laddr.rc_family = AF_BLUETOOTH; | 50 | laddr.rc_family = AF_BLUETOOTH; |
42 | laddr.rc_channel = 0; | 51 | laddr.rc_channel = 0; |
43 | 52 | ||
44 | if (bind(fd, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) { | 53 | if (bind(fd, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) { |
45 | dbgprintf("Can't bind socket\n"); | 54 | dbgprintf("Can't bind socket\n"); |
46 | close(fd); | 55 | close(fd); |
47 | return ERR_DEVICEOPENERROR; | 56 | return ERR_DEVICEOPENERROR; |
48 | } | 57 | } |
49 | 58 | ||
50 | str2ba(device, &bdaddr); | 59 | str2ba(device, &bdaddr); |
51 | bacpy(&raddr.rc_bdaddr, &bdaddr); | 60 | bacpy(&raddr.rc_bdaddr, &bdaddr); |
52 | raddr.rc_family = AF_BLUETOOTH; | 61 | raddr.rc_family = AF_BLUETOOTH; |
53 | raddr.rc_channel = port; | 62 | raddr.rc_channel = port; |
54 | 63 | ||
55 | if (connect(fd, (struct sockaddr *)&raddr, sizeof(raddr)) < 0) { | 64 | if (connect(fd, (struct sockaddr *)&raddr, sizeof(raddr)) < 0) { |
56 | dbgprintf("Can't connect\n"); | 65 | dbgprintf("Can't connect\n"); |
57 | close(fd); | 66 | close(fd); |
58 | return ERR_DEVICEOPENERROR; | 67 | return ERR_DEVICEOPENERROR; |
59 | } | 68 | } |
60 | 69 | ||
61 | d->hPhone = fd; | 70 | d->hPhone = fd; |
62 | return ERR_NONE; | 71 | return ERR_NONE; |
63 | } | 72 | } |
64 | 73 | ||
65 | #ifdef BLUETOOTH_RF_SEARCHING | 74 | #ifdef BLUETOOTH_RF_SEARCHING |
66 | 75 | ||
67 | struct search_context { | 76 | struct search_context { |
68 | char *svc; | 77 | char *svc; |
69 | uuid_t group; | 78 | uuid_t group; |
70 | int tree; | 79 | int tree; |
71 | uint32_t handle; | 80 | uint32_t handle; |
72 | }; | 81 | }; |
73 | 82 | ||
74 | static void print_service_desc(void *value, void *user) | 83 | static void print_service_desc(void *value, void *user) |
75 | { | 84 | { |
76 | sdp_data_t *p = (sdp_data_t *)value; | 85 | sdp_data_t *p = (sdp_data_t *)value; |
77 | int i = 0, proto = 0, *channel = (int *)user; | 86 | int i = 0, proto = 0, *channel = (int *)user; |
78 | 87 | ||
79 | for (; p; p = p->next, i++) { | 88 | for (; p; p = p->next, i++) { |
80 | switch (p->dtd) { | 89 | switch (p->dtd) { |
81 | case SDP_UUID16: | 90 | case SDP_UUID16: |
82 | case SDP_UUID32: | 91 | case SDP_UUID32: |
83 | case SDP_UUID128: | 92 | case SDP_UUID128: |
84 | proto = 1;//sdp_uuid_to_proto(&p->val.uuid); | 93 | proto = sdp_uuid_to_proto(&p->val.uuid); |
85 | break; | 94 | break; |
86 | case SDP_UINT8: | 95 | case SDP_UINT8: |
87 | if (proto == RFCOMM_UUID) { | 96 | if (proto == RFCOMM_UUID) { |
88 | (*channel) = p->val.uint8; | 97 | (*channel) = p->val.uint8; |
89 | return; | 98 | return; |
90 | } | 99 | } |
91 | break; | 100 | break; |
92 | } | 101 | } |
93 | } | 102 | } |
94 | } | 103 | } |
95 | 104 | ||
96 | void print_access_protos(value, user) | 105 | void print_access_protos(value, user) |
97 | { | 106 | { |
98 | sdp_list_t *protDescSeq = (sdp_list_t *)value; | 107 | sdp_list_t *protDescSeq = (sdp_list_t *)value; |
99 | int *channel = (int *)user; | 108 | int *channel = (int *)user; |
100 | 109 | ||
101 | sdp_list_foreach(protDescSeq,print_service_desc,channel); | 110 | sdp_list_foreach(protDescSeq,print_service_desc,channel); |
102 | } | 111 | } |
103 | 112 | ||
104 | static GSM_Error bluetooth_checkdevice(GSM_StateMachine *s, bdaddr_t *bdaddr, struct search_context *context) | 113 | static GSM_Error bluetooth_checkdevice(GSM_StateMachine *s, bdaddr_t *bdaddr, struct search_context *context) |
105 | { | 114 | { |
106 | sdp_session_t *sess; | 115 | sdp_session_t *sess; |
107 | sdp_list_t *attrid, *search, *seq, *next, *proto = 0; | ||
108 | uint32_t range = 0x0000ffff; | ||
109 | char str[20]; | ||
110 | sdp_record_t *rec; | 116 | sdp_record_t *rec; |
117 | sdp_list_t *attrid, *search, *seq, *next, *proto = 0; | ||
111 | sdp_data_t *d; | 118 | sdp_data_t *d; |
112 | bdaddr_t interface; | 119 | bdaddr_t interface; |
120 | uint32_t range = 0x0000ffff; | ||
113 | struct search_context subcontext; | 121 | struct search_context subcontext; |
122 | char str[20]; | ||
114 | int channel,channel2; | 123 | int channel,channel2; |
115 | 124 | ||
116 | bacpy(&interface,BDADDR_ANY); | 125 | bacpy(&interface,BDADDR_ANY); |
117 | 126 | ||
118 | ba2str(bdaddr, str); | 127 | ba2str(bdaddr, str); |
119 | smprintf(s,"%s\n", str); | 128 | smprintf(s,"%s\n", str); |
120 | 129 | ||
121 | sess = sdp_connect(&interface, bdaddr, SDP_RETRY_IF_BUSY); | 130 | sess = sdp_connect(&interface, bdaddr, SDP_RETRY_IF_BUSY); |
122 | if (!sess) { | 131 | if (!sess) { |
123 | dbgprintf("Failed to connect to SDP server on %s: %s\n", str, strerror(errno)); | 132 | dbgprintf("Failed to connect to SDP server on %s: %s\n", str, strerror(errno)); |
124 | return ERR_UNKNOWN; | 133 | return ERR_UNKNOWN; |
125 | } | 134 | } |
126 | 135 | ||
127 | attrid = sdp_list_append(0, &range); | 136 | attrid = sdp_list_append(0, &range); |
128 | search = sdp_list_append(0, &context->group); | 137 | search = sdp_list_append(0, &context->group); |
129 | if (sdp_service_search_attr_req(sess, search, SDP_ATTR_REQ_RANGE, attrid, &seq)) { | 138 | if (sdp_service_search_attr_req(sess, search, SDP_ATTR_REQ_RANGE, attrid, &seq)) { |
130 | dbgprintf("Service Search failed: %s\n", strerror(errno)); | 139 | dbgprintf("Service Search failed: %s\n", strerror(errno)); |
131 | sdp_close(sess); | 140 | sdp_close(sess); |
132 | return ERR_UNKNOWN; | 141 | return ERR_UNKNOWN; |
133 | } | 142 | } |
134 | sdp_list_free(attrid, 0); | 143 | sdp_list_free(attrid, 0); |
135 | sdp_list_free(search, 0); | 144 | sdp_list_free(search, 0); |
136 | 145 | ||
137 | channel2 = -1; | 146 | channel2 = -1; |
138 | for (; seq; seq = next) { | 147 | for (; seq; seq = next) { |
139 | rec = (sdp_record_t *) seq->data; | 148 | rec = (sdp_record_t *) seq->data; |
140 | 149 | ||
141 | if (channel2 == -1) { | 150 | if (channel2 == -1) { |
142 | if (!context->tree) { | 151 | if (!context->tree) { |
143 | d = sdp_data_get(rec,SDP_ATTR_SVCNAME_PRIMARY); | 152 | d = sdp_data_get(rec,SDP_ATTR_SVCNAME_PRIMARY); |
144 | 153 | ||
145 | if (false) { | 154 | if (sdp_get_access_protos(rec,&proto) == 0) { |
146 | channel = -1; | 155 | channel = -1; |
147 | sdp_list_foreach(proto,print_access_protos,&channel); | 156 | sdp_list_foreach(proto,print_access_protos,&channel); |
148 | //sdp_list_free(proto,(sdp_free_func_t)sdp_data_free); | 157 | sdp_list_free(proto,(sdp_free_func_t)sdp_data_free); |
149 | } | 158 | } |
150 | smprintf(s,"Channel %i",channel); | 159 | smprintf(s,"Channel %i",channel); |
151 | if (d) smprintf(s," - \"%s\"",d->val.str); | 160 | if (d) smprintf(s," - \"%s\"",d->val.str); |
152 | smprintf(s,"\n"); | 161 | smprintf(s,"\n"); |
153 | if (channel2 == -1 && bluetooth_checkservicename(s, d->val.str) == ERR_NONE) { | 162 | if (channel2 == -1 && bluetooth_checkservicename(s, d->val.str) == ERR_NONE) { |
154 | channel2 = channel; | 163 | channel2 = channel; |
155 | } | 164 | } |
156 | } | 165 | } |
157 | if (sdp_get_group_id(rec,&subcontext.group) != -1) { | 166 | if (sdp_get_group_id(rec,&subcontext.group) != -1) { |
158 | memcpy(&subcontext, context, sizeof(struct search_context)); | 167 | memcpy(&subcontext, context, sizeof(struct search_context)); |
159 | if (subcontext.group.value.uuid16 != context->group.value.uuid16) bluetooth_checkdevice(s,bdaddr,&subcontext); | 168 | if (subcontext.group.value.uuid16 != context->group.value.uuid16) bluetooth_checkdevice(s,bdaddr,&subcontext); |
160 | } | 169 | } |
161 | } | 170 | } |
162 | 171 | ||
163 | next = seq->next; | 172 | next = seq->next; |
164 | free(seq); | 173 | free(seq); |
165 | //sdp_record_free(rec); | 174 | sdp_record_free(rec); |
166 | } | 175 | } |
167 | sdp_close(sess); | 176 | sdp_close(sess); |
168 | 177 | ||
169 | if (channel2 != -1) return bluetooth_connect(s, channel2, str); | 178 | if (channel2 != -1) return bluetooth_connect(s, channel2, str); |
170 | 179 | ||
171 | return ERR_UNKNOWN; | 180 | return ERR_NOTSUPPORTED; |
172 | } | 181 | } |
173 | 182 | ||
174 | GSM_Error bluetooth_findchannel(GSM_StateMachine *s) | 183 | GSM_Error bluetooth_findchannel(GSM_StateMachine *s) |
175 | { | 184 | { |
176 | inquiry_info ii[20]; | 185 | inquiry_info ii[20]; |
177 | uint8_t count = 0; | 186 | uint8_t count = 0; |
178 | int i; | 187 | int i; |
179 | struct search_context context; | 188 | struct search_context context; |
180 | GSM_Error error = ERR_NOTSUPPORTED; | 189 | GSM_Error error = ERR_NOTSUPPORTED; |
181 | 190 | ||
182 | memset(&context, '\0', sizeof(struct search_context)); | 191 | memset(&context, '\0', sizeof(struct search_context)); |
183 | //sdp_uuid16_create(&(context.group),PUBLIC_BROWSE_GROUP); | 192 | sdp_uuid16_create(&(context.group),PUBLIC_BROWSE_GROUP); |
184 | 193 | ||
185 | if (!strcmp(s->CurrentConfig->Device,"/dev/ttyS1")) { | 194 | if (!strcmp(s->CurrentConfig->Device,"/dev/ttyS1")) { |
186 | dbgprintf("Searching for devices\n"); | 195 | dbgprintf("Searching for devices\n"); |
187 | if (sdp_general_inquiry(ii, 20, 8, &count) < 0) { | 196 | if (sdp_general_inquiry(ii, 20, 8, &count) < 0) { |
188 | return ERR_UNKNOWN; | 197 | return ERR_UNKNOWN; |
189 | } | 198 | } |
190 | } else { | 199 | } else { |
191 | count = 1; | 200 | count = 1; |
192 | str2ba(s->CurrentConfig->Device,&ii[0].bdaddr); | 201 | str2ba(s->CurrentConfig->Device,&ii[0].bdaddr); |
193 | } | 202 | } |
194 | for (i=0;i<count;i++) { | 203 | for (i=0;i<count;i++) { |
195 | error = bluetooth_checkdevice(s,&ii[i].bdaddr,&context); | 204 | error = bluetooth_checkdevice(s,&ii[i].bdaddr,&context); |
196 | if (error == ERR_NONE) return error; | 205 | if (error == ERR_NONE) return error; |
197 | } | 206 | } |
198 | return error; | 207 | return error; |
199 | } | 208 | } |
200 | 209 | ||
201 | #endif | 210 | #endif |
202 | #endif | 211 | #endif |
203 | #endif | 212 | #endif |
204 | 213 | ||
205 | /* How should editor hadle tabs in this file? Add editor commands here. | 214 | /* How should editor hadle tabs in this file? Add editor commands here. |
206 | * vim: noexpandtab sw=8 ts=8 sts=8: | 215 | * vim: noexpandtab sw=8 ts=8 sts=8: |
207 | */ | 216 | */ |
diff --git a/gammu/emb/common/device/devfunc.c b/gammu/emb/common/device/devfunc.c index d31ebbf..c58a01f 100644 --- a/gammu/emb/common/device/devfunc.c +++ b/gammu/emb/common/device/devfunc.c | |||
@@ -1,48 +1,56 @@ | |||
1 | /* Some source from Gnokii (www.gnokii.org) | ||
2 | * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot | ||
3 | * GNU GPL version 2 or later | ||
4 | */ | ||
5 | /* Some source from Minicom (http://alioth.debian.org/projects/minicom) | ||
6 | * (C) 1991,1992,1993,1994,1995,1996 by Miquel van Smoorenburg | ||
7 | * GNU GPL version 2 | ||
8 | */ | ||
1 | 9 | ||
2 | #include <string.h> | 10 | #include <string.h> |
3 | #ifdef WIN32 | 11 | #ifdef WIN32 |
4 | # include <io.h> | 12 | # include <io.h> |
5 | #else | 13 | #else |
6 | # include <errno.h> | 14 | # include <errno.h> |
7 | # include <signal.h> | 15 | # include <signal.h> |
8 | #endif | 16 | #endif |
9 | 17 | ||
10 | #include "../gsmstate.h" | 18 | #include "../gsmstate.h" |
11 | 19 | ||
12 | #ifdef GSM_ENABLE_BLUETOOTHDEVICE | 20 | #ifdef GSM_ENABLE_BLUETOOTHDEVICE |
13 | #ifdef BLUETOOTH_RF_SEARCHING | 21 | #ifdef BLUETOOTH_RF_SEARCHING |
14 | 22 | ||
15 | GSM_Error bluetooth_checkservicename(GSM_StateMachine *s, char *name) | 23 | GSM_Error bluetooth_checkservicename(GSM_StateMachine *s, char *name) |
16 | { | 24 | { |
17 | if (s->ConnectionType == GCT_BLUEPHONET && strstr(name,"Nokia PC Suite")!=NULL) return ERR_NONE; | 25 | if (s->ConnectionType == GCT_BLUEPHONET && strstr(name,"Nokia PC Suite")!=NULL) return ERR_NONE; |
18 | if (s->ConnectionType == GCT_BLUEOBEX && strstr(name,"OBEX") !=NULL) return ERR_NONE; | 26 | if (s->ConnectionType == GCT_BLUEOBEX && strstr(name,"OBEX") !=NULL) return ERR_NONE; |
19 | if (s->ConnectionType == GCT_BLUEAT && strstr(name,"COM 1") !=NULL) return ERR_NONE; | 27 | if (s->ConnectionType == GCT_BLUEAT && strstr(name,"COM 1") !=NULL) return ERR_NONE; |
20 | return ERR_UNKNOWN; | 28 | return ERR_UNKNOWN; |
21 | } | 29 | } |
22 | 30 | ||
23 | #endif | 31 | #endif |
24 | #endif | 32 | #endif |
25 | 33 | ||
26 | #if defined (GSM_ENABLE_BLUETOOTHDEVICE) || defined (GSM_ENABLE_IRDADEVICE) | 34 | #if defined (GSM_ENABLE_BLUETOOTHDEVICE) || defined (GSM_ENABLE_IRDADEVICE) |
27 | 35 | ||
28 | int socket_read(GSM_StateMachine *s, void *buf, size_t nbytes, int hPhone) | 36 | int socket_read(GSM_StateMachine *s, void *buf, size_t nbytes, int hPhone) |
29 | { | 37 | { |
30 | fd_set readfds; | 38 | fd_set readfds; |
31 | #ifdef WIN32 | 39 | #ifdef WIN32 |
32 | struct timeval timer; | 40 | struct timeval timer; |
33 | #endif | 41 | #endif |
34 | 42 | ||
35 | FD_ZERO(&readfds); | 43 | FD_ZERO(&readfds); |
36 | FD_SET(hPhone, &readfds); | 44 | FD_SET(hPhone, &readfds); |
37 | #ifndef WIN32 | 45 | #ifndef WIN32 |
38 | if (select(hPhone+1, &readfds, NULL, NULL, 0)) { | 46 | if (select(hPhone+1, &readfds, NULL, NULL, 0)) { |
39 | return(read(hPhone, buf, nbytes)); | 47 | return(read(hPhone, buf, nbytes)); |
40 | } | 48 | } |
41 | #else | 49 | #else |
42 | memset(&timer,0,sizeof(timer)); | 50 | memset(&timer,0,sizeof(timer)); |
43 | if (select(0, &readfds, NULL, NULL, &timer) != 0) { | 51 | if (select(0, &readfds, NULL, NULL, &timer) != 0) { |
44 | return(recv(hPhone, buf, nbytes, 0)); | 52 | return(recv(hPhone, buf, nbytes, 0)); |
45 | } | 53 | } |
46 | #endif | 54 | #endif |
47 | return 0; | 55 | return 0; |
48 | } | 56 | } |
@@ -60,97 +68,97 @@ int socket_write(GSM_StateMachine *s, void *buf, size_t nbytes, int hPhone) | |||
60 | ret = send(hPhone, buf, nbytes - actual, 0); | 68 | ret = send(hPhone, buf, nbytes - actual, 0); |
61 | if (ret < 0) { | 69 | if (ret < 0) { |
62 | if (actual != nbytes) GSM_OSErrorInfo(s,"socket_write"); | 70 | if (actual != nbytes) GSM_OSErrorInfo(s,"socket_write"); |
63 | return actual; | 71 | return actual; |
64 | } | 72 | } |
65 | actual += ret; | 73 | actual += ret; |
66 | buf += ret; | 74 | buf += ret; |
67 | } while (actual < nbytes); | 75 | } while (actual < nbytes); |
68 | 76 | ||
69 | return actual; | 77 | return actual; |
70 | } | 78 | } |
71 | 79 | ||
72 | GSM_Error socket_close(GSM_StateMachine *s, int hPhone) | 80 | GSM_Error socket_close(GSM_StateMachine *s, int hPhone) |
73 | { | 81 | { |
74 | shutdown(hPhone, 0); | 82 | shutdown(hPhone, 0); |
75 | #ifdef WIN32 | 83 | #ifdef WIN32 |
76 | closesocket(hPhone); /*FIXME: error checking */ | 84 | closesocket(hPhone); /*FIXME: error checking */ |
77 | #else | 85 | #else |
78 | close(hPhone); /*FIXME: error checking */ | 86 | close(hPhone); /*FIXME: error checking */ |
79 | #endif | 87 | #endif |
80 | return ERR_NONE; | 88 | return ERR_NONE; |
81 | } | 89 | } |
82 | 90 | ||
83 | #endif | 91 | #endif |
84 | 92 | ||
85 | #ifdef ENABLE_LGPL | 93 | #ifdef ENABLE_LGPL |
86 | 94 | ||
87 | GSM_Error lock_device(const char* port, char **lock_device) | 95 | GSM_Error lock_device(const char* port, char **lock_device) |
88 | { | 96 | { |
89 | *lock_device = 0; | 97 | *lock_device = 0; |
90 | return ERR_NONE; | 98 | return ERR_NONE; |
91 | } | 99 | } |
92 | 100 | ||
93 | bool unlock_device(char **lock_file) | 101 | bool unlock_device(char **lock_file) |
94 | { | 102 | { |
95 | return true; | 103 | return true; |
96 | } | 104 | } |
97 | 105 | ||
98 | #else | 106 | #else |
99 | 107 | ||
100 | #define max_buf_len 128 | 108 | #define max_buf_len 128 |
101 | #define lock_path "/var/lock/LCK.." | 109 | #define lock_path "/var/lock/LCK.." |
102 | 110 | ||
103 | /* Lock the device. Allocated string with a lock name is returned | 111 | /* Lock the device. Allocated string with a lock name is returned |
104 | * in lock_device | 112 | * in lock_device |
105 | */ | 113 | */ |
106 | GSM_Error lock_device(const char* port, char **lock_device) | 114 | GSM_Error lock_device(const char* port, char **lock_device) |
107 | { | 115 | { |
108 | #ifndef WIN32 | 116 | #if !defined(WIN32) && !defined(DJGPP) |
109 | char *lock_file = NULL; | 117 | char *lock_file = NULL; |
110 | char buffer[max_buf_len]; | 118 | char buffer[max_buf_len]; |
111 | const char *aux; | 119 | const char *aux; |
112 | int fd, len; | 120 | int fd, len; |
113 | GSM_Errorerror = ERR_NONE; | 121 | GSM_Errorerror = ERR_NONE; |
114 | 122 | ||
115 | dbgprintf("Locking device\n"); | 123 | dbgprintf("Locking device\n"); |
116 | 124 | ||
117 | aux = strrchr(port, '/'); | 125 | aux = strrchr(port, '/'); |
118 | /* Remove leading '/' */ | 126 | /* Remove leading '/' */ |
119 | if (aux) { | 127 | if (aux) { |
120 | aux++; | 128 | aux++; |
121 | } else { | 129 | } else { |
122 | /* No / in port */ | 130 | /* No / in port */ |
123 | aux = port; | 131 | aux = port; |
124 | } | 132 | } |
125 | len = strlen(aux) + strlen(lock_path); | 133 | len = strlen(aux) + strlen(lock_path); |
126 | 134 | ||
127 | memset(buffer, 0, sizeof(buffer)); | 135 | memset(buffer, 0, sizeof(buffer)); |
128 | lock_file = calloc(len + 1, 1); | 136 | lock_file = calloc(len + 1, 1); |
129 | if (!lock_file) { | 137 | if (!lock_file) { |
130 | dbgprintf("Out of memory error while locking device\n"); | 138 | dbgprintf("Out of memory error while locking device\n"); |
131 | return ERR_MOREMEMORY; | 139 | return ERR_MOREMEMORY; |
132 | } | 140 | } |
133 | /* I think we don't need to use strncpy, as we should have enough | 141 | /* I think we don't need to use strncpy, as we should have enough |
134 | * buffer due to strlen results | 142 | * buffer due to strlen results |
135 | */ | 143 | */ |
136 | strcpy(lock_file, lock_path); | 144 | strcpy(lock_file, lock_path); |
137 | strcat(lock_file, aux); | 145 | strcat(lock_file, aux); |
138 | 146 | ||
139 | /* Check for the stale lockfile. | 147 | /* Check for the stale lockfile. |
140 | * The code taken from minicom by Miquel van Smoorenburg */ | 148 | * The code taken from minicom by Miquel van Smoorenburg */ |
141 | if ((fd = open(lock_file, O_RDONLY)) >= 0) { | 149 | if ((fd = open(lock_file, O_RDONLY)) >= 0) { |
142 | char buf[max_buf_len]; | 150 | char buf[max_buf_len]; |
143 | int pid, n = 0; | 151 | int pid, n = 0; |
144 | 152 | ||
145 | n = read(fd, buf, sizeof(buf) - 1); | 153 | n = read(fd, buf, sizeof(buf) - 1); |
146 | close(fd); | 154 | close(fd); |
147 | if (n > 0) { | 155 | if (n > 0) { |
148 | pid = -1; | 156 | pid = -1; |
149 | if (n == 4) | 157 | if (n == 4) |
150 | /* Kermit-style lockfile. */ | 158 | /* Kermit-style lockfile. */ |
151 | pid = *(int *)buf; | 159 | pid = *(int *)buf; |
152 | else { | 160 | else { |
153 | /* Ascii lockfile. */ | 161 | /* Ascii lockfile. */ |
154 | buf[n] = 0; | 162 | buf[n] = 0; |
155 | sscanf(buf, "%d", &pid); | 163 | sscanf(buf, "%d", &pid); |
156 | } | 164 | } |
@@ -173,94 +181,94 @@ GSM_Error lock_device(const char* port, char **lock_device) | |||
173 | /* no wrong permissions are set. only reason could be */ | 181 | /* no wrong permissions are set. only reason could be */ |
174 | /* flock/lockf or a empty lockfile due to a broken binary */ | 182 | /* flock/lockf or a empty lockfile due to a broken binary */ |
175 | /* which is more likely */ | 183 | /* which is more likely */ |
176 | if (n == 0) { | 184 | if (n == 0) { |
177 | dbgprintf("Unable to read lockfile %s.\n", lock_file); | 185 | dbgprintf("Unable to read lockfile %s.\n", lock_file); |
178 | dbgprintf("Please check for reason and remove the lockfile by hand.\n"); | 186 | dbgprintf("Please check for reason and remove the lockfile by hand.\n"); |
179 | dbgprintf("Cannot lock device\n"); | 187 | dbgprintf("Cannot lock device\n"); |
180 | error = ERR_UNKNOWN; | 188 | error = ERR_UNKNOWN; |
181 | goto failed; | 189 | goto failed; |
182 | } | 190 | } |
183 | } | 191 | } |
184 | 192 | ||
185 | /* Try to create a new file, with 0644 mode */ | 193 | /* Try to create a new file, with 0644 mode */ |
186 | fd = open(lock_file, O_CREAT | O_EXCL | O_WRONLY, 0644); | 194 | fd = open(lock_file, O_CREAT | O_EXCL | O_WRONLY, 0644); |
187 | if (fd == -1) { | 195 | if (fd == -1) { |
188 | if (errno == EEXIST) { | 196 | if (errno == EEXIST) { |
189 | dbgprintf("Device seems to be locked by unknown process\n"); | 197 | dbgprintf("Device seems to be locked by unknown process\n"); |
190 | error = ERR_DEVICEOPENERROR; | 198 | error = ERR_DEVICEOPENERROR; |
191 | } else if (errno == EACCES) { | 199 | } else if (errno == EACCES) { |
192 | dbgprintf("Please check permission on lock directory\n"); | 200 | dbgprintf("Please check permission on lock directory\n"); |
193 | error = ERR_PERMISSION; | 201 | error = ERR_PERMISSION; |
194 | } else if (errno == ENOENT) { | 202 | } else if (errno == ENOENT) { |
195 | dbgprintf("Cannot create lockfile %s. Please check for existence of path\n", lock_file); | 203 | dbgprintf("Cannot create lockfile %s. Please check for existence of path\n", lock_file); |
196 | error = ERR_UNKNOWN; | 204 | error = ERR_UNKNOWN; |
197 | } else { | 205 | } else { |
198 | dbgprintf("Unknown error with creating lockfile %s\n", lock_file); | 206 | dbgprintf("Unknown error with creating lockfile %s\n", lock_file); |
199 | error = ERR_UNKNOWN; | 207 | error = ERR_UNKNOWN; |
200 | } | 208 | } |
201 | goto failed; | 209 | goto failed; |
202 | } | 210 | } |
203 | sprintf(buffer, "%10ld gammu\n", (long)getpid()); | 211 | sprintf(buffer, "%10ld gammu\n", (long)getpid()); |
204 | write(fd, buffer, strlen(buffer)); | 212 | write(fd, buffer, strlen(buffer)); |
205 | close(fd); | 213 | close(fd); |
206 | *lock_device = lock_file; | 214 | *lock_device = lock_file; |
207 | return ERR_NONE; | 215 | return ERR_NONE; |
208 | failed: | 216 | failed: |
209 | free(lock_file); | 217 | free(lock_file); |
210 | *lock_device = 0; | 218 | *lock_device = 0; |
211 | return error; | 219 | return error; |
212 | #else | 220 | #else |
213 | *lock_device = 0; | 221 | *lock_device = 0; |
214 | return ERR_NONE; | 222 | return ERR_NONE; |
215 | #endif | 223 | #endif |
216 | } | 224 | } |
217 | 225 | ||
218 | /* Removes lock and frees memory */ | 226 | /* Removes lock and frees memory */ |
219 | bool unlock_device(char **lock_file) | 227 | bool unlock_device(char **lock_file) |
220 | { | 228 | { |
221 | #ifndef WIN32 | 229 | #if !defined(WIN32) && !defined(DJGPP) |
222 | int err; | 230 | int err; |
223 | 231 | ||
224 | if (!lock_file) { | 232 | if (!lock_file) { |
225 | dbgprintf("Cannot unlock device\n"); | 233 | dbgprintf("Cannot unlock device\n"); |
226 | return false; | 234 | return false; |
227 | } | 235 | } |
228 | err = unlink(*lock_file); | 236 | err = unlink(*lock_file); |
229 | free(*lock_file); | 237 | free(*lock_file); |
230 | *lock_file = NULL; | 238 | *lock_file = NULL; |
231 | return (err + 1); | 239 | return (err + 1); |
232 | #else | 240 | #else |
233 | return true; | 241 | return true; |
234 | #endif | 242 | #endif |
235 | } | 243 | } |
236 | 244 | ||
237 | #endif | 245 | #endif |
238 | 246 | ||
239 | int FindSerialSpeed(char *buffer) | 247 | int FindSerialSpeed(char *buffer) |
240 | { | 248 | { |
241 | switch (atoi(buffer)) { | 249 | switch (atoi(buffer)) { |
242 | case 50 : return 50; | 250 | case 50 : return 50; |
243 | case 75 : return 75; | 251 | case 75 : return 75; |
244 | case 110: return 110; | 252 | case 110: return 110; |
245 | case 134: return 134; | 253 | case 134: return 134; |
246 | case 150: return 150; | 254 | case 150: return 150; |
247 | case 200: return 200; | 255 | case 200: return 200; |
248 | case 300: return 300; | 256 | case 300: return 300; |
249 | case 600: return 600; | 257 | case 600: return 600; |
250 | case 1200: return 1200; | 258 | case 1200: return 1200; |
251 | case 1800: return 1800; | 259 | case 1800: return 1800; |
252 | case 2400: return 2400; | 260 | case 2400: return 2400; |
253 | case 4800: return 4800; | 261 | case 4800: return 4800; |
254 | case 9600: return 9600; | 262 | case 9600: return 9600; |
255 | case 19200: return 19200; | 263 | case 19200: return 19200; |
256 | case 38400: return 38400; | 264 | case 38400: return 38400; |
257 | case 57600: return 57600; | 265 | case 57600: return 57600; |
258 | case 115200: return 115200; | 266 | case 115200: return 115200; |
259 | case 230400: return 230400; | 267 | case 230400: return 230400; |
260 | default : return 0; | 268 | default : return 0; |
261 | } | 269 | } |
262 | } | 270 | } |
263 | 271 | ||
264 | /* How should editor hadle tabs in this file? Add editor commands here. | 272 | /* How should editor hadle tabs in this file? Add editor commands here. |
265 | * vim: noexpandtab sw=8 ts=8 sts=8: | 273 | * vim: noexpandtab sw=8 ts=8 sts=8: |
266 | */ | 274 | */ |
diff --git a/gammu/emb/common/device/irda/irda.c b/gammu/emb/common/device/irda/irda.c index fef50ac..e680377 100644 --- a/gammu/emb/common/device/irda/irda.c +++ b/gammu/emb/common/device/irda/irda.c | |||
@@ -1,51 +1,55 @@ | |||
1 | /* (c) 2001-2004 by Marcin Wiacek */ | 1 | /* (c) 2001-2004 by Marcin Wiacek */ |
2 | /* based on some work from Ralf Thelen and MyGnokii */ | 2 | /* based on some work from Ralf Thelen and MyGnokii (www.mwiacek.com) */ |
3 | /* based on some work from Gnokii and MSDN */ | 3 | /* based on some work from MSDN */ |
4 | /* based on some work from Gnokii (www.gnokii.org) | ||
5 | * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot | ||
6 | * GNU GPL version 2 or later | ||
7 | */ | ||
4 | 8 | ||
5 | /* You have to include wsock32.lib library to MS VC project to compile it */ | 9 | /* You have to include wsock32.lib library to MS VC project to compile it */ |
6 | 10 | ||
7 | #include "../../gsmstate.h" | 11 | #include "../../gsmstate.h" |
8 | 12 | ||
9 | #ifdef GSM_ENABLE_IRDADEVICE | 13 | #ifdef GSM_ENABLE_IRDADEVICE |
10 | #ifndef DJGPP | 14 | #ifndef DJGPP |
11 | 15 | ||
12 | #ifndef WIN32 | 16 | #ifndef WIN32 |
13 | # include <stdlib.h> | 17 | # include <stdlib.h> |
14 | # include <unistd.h> | 18 | # include <unistd.h> |
15 | # include <stdio.h> | 19 | # include <stdio.h> |
16 | # include <fcntl.h> | 20 | # include <fcntl.h> |
17 | # include <errno.h> | 21 | # include <errno.h> |
18 | # include <string.h> | 22 | # include <string.h> |
19 | # include <sys/time.h> | 23 | # include <sys/time.h> |
20 | # include <sys/poll.h> | 24 | # include <sys/poll.h> |
21 | # include <sys/socket.h> | 25 | # include <sys/socket.h> |
22 | # include <sys/ioctl.h> | 26 | # include <sys/ioctl.h> |
23 | #else | 27 | #else |
24 | # include <windows.h> | 28 | # include <windows.h> |
25 | # include <io.h> | 29 | # include <io.h> |
26 | #endif | 30 | #endif |
27 | 31 | ||
28 | #include "../../gsmcomon.h" | 32 | #include "../../gsmcomon.h" |
29 | #include "../devfunc.h" | 33 | #include "../devfunc.h" |
30 | #include "irda.h" | 34 | #include "irda.h" |
31 | 35 | ||
32 | static bool irda_discover_device(GSM_StateMachine *state) | 36 | static bool irda_discover_device(GSM_StateMachine *state) |
33 | { | 37 | { |
34 | GSM_Device_IrdaData *d = &state->Device.Data.Irda; | 38 | GSM_Device_IrdaData *d = &state->Device.Data.Irda; |
35 | struct irda_device_list*list; | 39 | struct irda_device_list*list; |
36 | unsigned char *buf; | 40 | unsigned char *buf; |
37 | unsigned int sec; | 41 | unsigned int sec; |
38 | int s, z, len, fd, i; | 42 | int s, z, len, fd, i; |
39 | GSM_DateTime Date; | 43 | GSM_DateTime Date; |
40 | bool founddevice = false; | 44 | bool founddevice = false; |
41 | #ifdef WIN32 | 45 | #ifdef WIN32 |
42 | int index; | 46 | int index; |
43 | #endif | 47 | #endif |
44 | 48 | ||
45 | fd = socket(AF_IRDA, SOCK_STREAM, 0); | 49 | fd = socket(AF_IRDA, SOCK_STREAM, 0); |
46 | 50 | ||
47 | /* can handle maximally 10 devices during discovering */ | 51 | /* can handle maximally 10 devices during discovering */ |
48 | len = sizeof(struct irda_device_list) + sizeof(struct irda_device_info) * 10; | 52 | len = sizeof(struct irda_device_list) + sizeof(struct irda_device_info) * 10; |
49 | buf = malloc(len); | 53 | buf = malloc(len); |
50 | list = (struct irda_device_list *)buf; | 54 | list = (struct irda_device_list *)buf; |
51 | 55 | ||
diff --git a/gammu/emb/common/device/irda/irda_unx.h b/gammu/emb/common/device/irda/irda_unx.h index 8dbcb97..7a55273 100644 --- a/gammu/emb/common/device/irda/irda_unx.h +++ b/gammu/emb/common/device/irda/irda_unx.h | |||
@@ -1,49 +1,49 @@ | |||
1 | /* part of irda.h available in Linux kernel source */ | 1 | /* part of irda.h available in Linux kernel source (www.kernel.org) */ |
2 | 2 | ||
3 | /********************************************************************* | 3 | /********************************************************************* |
4 | * | 4 | * |
5 | * Filename: irda.h | 5 | * Filename: irda.h |
6 | * Version: | 6 | * Version: |
7 | * Description: | 7 | * Description: |
8 | * Status: Experimental. | 8 | * Status: Experimental. |
9 | * Author: Dag Brattli <dagb@cs.uit.no> | 9 | * Author: Dag Brattli <dagb@cs.uit.no> |
10 | * Created at: Mon Mar 8 14:06:12 1999 | 10 | * Created at: Mon Mar 8 14:06:12 1999 |
11 | * Modified at: Sat Dec 25 16:06:42 1999 | 11 | * Modified at: Sat Dec 25 16:06:42 1999 |
12 | * Modified by: Dag Brattli <dagb@cs.uit.no> | 12 | * Modified by: Dag Brattli <dagb@cs.uit.no> |
13 | * | 13 | * |
14 | * Copyright (c) 1999 Dag Brattli, All Rights Reserved. | 14 | * Copyright (c) 1999 Dag Brattli, All Rights Reserved. |
15 | * | 15 | * |
16 | * This program is free software; you can redistribute it and/or | 16 | * This program is free software; you can redistribute it and/or |
17 | * modify it under the terms of the GNU General Public License as | 17 | * modify it under the terms of the GNU General Public License as |
18 | * published by the Free Software Foundation; either version 2 of | 18 | * published by the Free Software Foundation; either version 2 of |
19 | * the License, or (at your option) any later version. | 19 | * the License, or (at your option) any later version. |
20 | * | 20 | * |
21 | * Neither Dag Brattli nor University of Tromsø admit liability nor | 21 | * Neither Dag Brattli nor University of Tromsø admit liability nor |
22 | * provide warranty for any of this software. This material is | 22 | * provide warranty for any of this software. This material is |
23 | * provided "AS-IS" and at no charge. | 23 | * provided "AS-IS" and at no charge. |
24 | * | 24 | * |
25 | ********************************************************************/ | 25 | ********************************************************************/ |
26 | 26 | ||
27 | #ifndef __irda_unx_h | 27 | #ifndef __irda_unx_h |
28 | #define __irda_unx_h | 28 | #define __irda_unx_h |
29 | 29 | ||
30 | #include <sys/types.h> | 30 | #include <sys/types.h> |
31 | #include <sys/socket.h> | 31 | #include <sys/socket.h> |
32 | 32 | ||
33 | #define SOL_IRLMP 266 /* Same as SOL_IRDA for now */ | 33 | #define SOL_IRLMP 266 /* Same as SOL_IRDA for now */ |
34 | #define IRLMP_ENUMDEVICES 1 /* Return discovery log */ | 34 | #define IRLMP_ENUMDEVICES 1 /* Return discovery log */ |
35 | #define LSAP_ANY 0xff | 35 | #define LSAP_ANY 0xff |
36 | 36 | ||
37 | struct sockaddr_irda { | 37 | struct sockaddr_irda { |
38 | sa_family_t irdaAddressFamily;/* AF_IRDA */ | 38 | sa_family_t irdaAddressFamily;/* AF_IRDA */ |
39 | u_int8_t sir_lsap_sel; /* LSAP selector */ | 39 | u_int8_t sir_lsap_sel; /* LSAP selector */ |
40 | u_int32_t irdaDeviceID; /* Device address */ | 40 | u_int32_t irdaDeviceID; /* Device address */ |
41 | char irdaServiceName[25]; /* Usually <service>:IrDA:TinyTP */ | 41 | char irdaServiceName[25]; /* Usually <service>:IrDA:TinyTP */ |
42 | }; | 42 | }; |
43 | 43 | ||
44 | struct irda_device_info { | 44 | struct irda_device_info { |
45 | u_int32_t saddr; /* Address of local interface */ | 45 | u_int32_t saddr; /* Address of local interface */ |
46 | u_int32_t irdaDeviceID; /* Address of remote device */ | 46 | u_int32_t irdaDeviceID; /* Address of remote device */ |
47 | char irdaDeviceName[22]; /* Description */ | 47 | char irdaDeviceName[22]; /* Description */ |
48 | u_int8_t charset; /* Charset used for description */ | 48 | u_int8_t charset; /* Charset used for description */ |
49 | u_int8_t hints[2]; /* Hint bits */ | 49 | u_int8_t hints[2]; /* Hint bits */ |
diff --git a/gammu/emb/common/device/serial/ser_djg.c b/gammu/emb/common/device/serial/ser_djg.c index ac9d7c8..2524187 100644 --- a/gammu/emb/common/device/serial/ser_djg.c +++ b/gammu/emb/common/device/serial/ser_djg.c | |||
@@ -1,74 +1,74 @@ | |||
1 | 1 | ||
2 | #include "../../gsmstate.h" | 2 | #include "../../gsmstate.h" |
3 | 3 | ||
4 | #ifdef GSM_ENABLE_SERIALDEVICE | 4 | #ifdef GSM_ENABLE_SERIALDEVICE |
5 | #ifdef DJGPP | 5 | #ifdef DJGPP |
6 | 6 | ||
7 | #include "../../gsmcomon.h" | 7 | #include "../../gsmcomon.h" |
8 | #include "ser_djg.h" | 8 | #include "ser_djg.h" |
9 | 9 | ||
10 | static GSM_Error serial_close(GSM_StateMachine *s) | 10 | static GSM_Error serial_close(GSM_StateMachine *s) |
11 | { | 11 | { |
12 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 12 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
13 | 13 | ||
14 | return ERR_NONE; | 14 | return ERR_NOTIMPLEMENTED; |
15 | } | 15 | } |
16 | 16 | ||
17 | static GSM_Error serial_open (GSM_StateMachine *s) | 17 | static GSM_Error serial_open (GSM_StateMachine *s) |
18 | { | 18 | { |
19 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 19 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
20 | 20 | ||
21 | return ERR_NONE; | 21 | return ERR_NOTIMPLEMENTED; |
22 | } | 22 | } |
23 | 23 | ||
24 | static GSM_Error serial_setparity(GSM_StateMachine *s, bool parity) | 24 | static GSM_Error serial_setparity(GSM_StateMachine *s, bool parity) |
25 | { | 25 | { |
26 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 26 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
27 | 27 | ||
28 | return ERR_NONE; | 28 | return ERR_NOTIMPLEMENTED; |
29 | } | 29 | } |
30 | 30 | ||
31 | static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts) | 31 | static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts) |
32 | { | 32 | { |
33 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 33 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
34 | 34 | ||
35 | return ERR_NONE; | 35 | return ERR_NOTIMPLEMENTED; |
36 | } | 36 | } |
37 | 37 | ||
38 | static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed) | 38 | static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed) |
39 | { | 39 | { |
40 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 40 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
41 | 41 | ||
42 | return ERR_NONE; | 42 | return ERR_NOTIMPLEMENTED; |
43 | } | 43 | } |
44 | 44 | ||
45 | static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes) | 45 | static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes) |
46 | { | 46 | { |
47 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 47 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
48 | 48 | ||
49 | return 0; | 49 | return 0; |
50 | } | 50 | } |
51 | 51 | ||
52 | static int serial_write(GSM_StateMachine *s, void *buf, size_t nbytes) | 52 | static int serial_write(GSM_StateMachine *s, void *buf, size_t nbytes) |
53 | { | 53 | { |
54 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 54 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
55 | 55 | ||
56 | return 0; | 56 | return 0; |
57 | } | 57 | } |
58 | 58 | ||
59 | GSM_Device_Functions SerialDevice = { | 59 | GSM_Device_Functions SerialDevice = { |
60 | serial_open, | 60 | serial_open, |
61 | serial_close, | 61 | serial_close, |
62 | serial_setparity, | 62 | serial_setparity, |
63 | serial_setdtrrts, | 63 | serial_setdtrrts, |
64 | serial_setspeed, | 64 | serial_setspeed, |
65 | serial_read, | 65 | serial_read, |
66 | serial_write | 66 | serial_write |
67 | }; | 67 | }; |
68 | 68 | ||
69 | #endif | 69 | #endif |
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | /* How should editor hadle tabs in this file? Add editor commands here. | 72 | /* How should editor hadle tabs in this file? Add editor commands here. |
73 | * vim: noexpandtab sw=8 ts=8 sts=8: | 73 | * vim: noexpandtab sw=8 ts=8 sts=8: |
74 | */ | 74 | */ |
diff --git a/gammu/emb/common/device/serial/ser_unx.c b/gammu/emb/common/device/serial/ser_unx.c index 2a87b11..69c7515 100644 --- a/gammu/emb/common/device/serial/ser_unx.c +++ b/gammu/emb/common/device/serial/ser_unx.c | |||
@@ -1,83 +1,107 @@ | |||
1 | /* (c) 2002-2004 by Marcin Wiacek */ | 1 | /* (c) 2002-2004 by Marcin Wiacek */ |
2 | /* locking device and settings all speeds by Michal Cihar */ | 2 | /* locking device and settings all speeds by Michal Cihar */ |
3 | /* based on some work from Gnokii (www.gnokii.org) | ||
4 | * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot | ||
5 | * GNU GPL version 2 or later | ||
6 | */ | ||
3 | 7 | ||
4 | #include "../../gsmstate.h" | 8 | #include "../../gsmstate.h" |
5 | 9 | ||
6 | #ifdef GSM_ENABLE_SERIALDEVICE | 10 | #ifdef GSM_ENABLE_SERIALDEVICE |
7 | #ifndef WIN32 | 11 | #ifndef WIN32 |
8 | #ifndef DJGPP | 12 | #ifndef DJGPP |
9 | 13 | ||
10 | #include <sys/file.h> | 14 | #include <sys/file.h> |
11 | #include <sys/time.h> | 15 | #include <sys/time.h> |
12 | #include <string.h> | 16 | #include <string.h> |
13 | #include <termios.h> | 17 | #include <termios.h> |
14 | #include <errno.h> | 18 | #include <errno.h> |
15 | 19 | ||
16 | #include "../../gsmcomon.h" | 20 | #include "../../gsmcomon.h" |
17 | #include "ser_unx.h" | 21 | #include "ser_unx.h" |
18 | 22 | ||
23 | #ifndef O_NONBLOCK | ||
24 | # define O_NONBLOCK 0 | ||
25 | #endif | ||
26 | |||
27 | #ifdef __NetBSD__ | ||
28 | # define FNONBLOCK O_NONBLOCK | ||
29 | |||
30 | # define B57600 0010001 | ||
31 | # define B115200 0010002 | ||
32 | # define B230400 0010003 | ||
33 | # define B460800 0010004 | ||
34 | # define B500000 0010005 | ||
35 | # define B576000 0010006 | ||
36 | # define B921600 0010007 | ||
37 | # define B1000000 0010010 | ||
38 | # define B1152000 0010011 | ||
39 | # define B1500000 0010012 | ||
40 | # define B2000000 0010013 | ||
41 | # define B2500000 0010014 | ||
42 | # define B3000000 0010015 | ||
43 | # define B3500000 0010016 | ||
44 | # define B4000000 0010017 | ||
45 | #endif | ||
46 | |||
19 | static GSM_Error serial_close(GSM_StateMachine *s) | 47 | static GSM_Error serial_close(GSM_StateMachine *s) |
20 | { | 48 | { |
21 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 49 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
22 | 50 | ||
23 | /* Restores old settings */ | 51 | /* Restores old settings */ |
24 | tcsetattr(d->hPhone, TCSANOW, &d->old_settings); | 52 | tcsetattr(d->hPhone, TCSANOW, &d->old_settings); |
25 | 53 | ||
26 | /* Closes device */ | 54 | /* Closes device */ |
27 | close(d->hPhone); | 55 | close(d->hPhone); |
28 | 56 | ||
29 | return ERR_NONE; | 57 | return ERR_NONE; |
30 | } | 58 | } |
31 | 59 | ||
32 | #ifndef O_NONBLOCK | ||
33 | # define O_NONBLOCK 0 | ||
34 | #endif | ||
35 | |||
36 | static GSM_Error serial_open (GSM_StateMachine *s) | 60 | static GSM_Error serial_open (GSM_StateMachine *s) |
37 | { | 61 | { |
38 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 62 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
39 | struct termios t; | 63 | struct termios t; |
40 | int i; | 64 | int i; |
41 | 65 | ||
42 | /* O_NONBLOCK MUST is required to avoid waiting for DCD */ | 66 | /* O_NONBLOCK MUST is required to avoid waiting for DCD */ |
43 | d->hPhone = open(s->CurrentConfig->Device, O_RDWR | O_NOCTTY | O_NONBLOCK); | 67 | d->hPhone = open(s->CurrentConfig->Device, O_RDWR | O_NOCTTY | O_NONBLOCK); |
44 | if (d->hPhone < 0) { | 68 | if (d->hPhone < 0) { |
45 | i = errno; | 69 | i = errno; |
46 | GSM_OSErrorInfo(s,"open in serial_open"); | 70 | GSM_OSErrorInfo(s,"open in serial_open"); |
47 | if (i == 2) return ERR_DEVICENOTEXIST; //no such file or directory | 71 | if (i == 2) return ERR_DEVICENOTEXIST; //no such file or directory |
48 | if (i == 13) return ERR_DEVICENOPERMISSION;//permission denied | 72 | if (i == 13) return ERR_DEVICENOPERMISSION;//permission denied |
49 | return ERR_DEVICEOPENERROR; | 73 | return ERR_DEVICEOPENERROR; |
50 | } | 74 | } |
51 | 75 | ||
52 | #ifdef TIOCEXCL | 76 | #ifdef TIOCEXCL |
53 | /* open() calls from other applications shall fail now */ | 77 | /* open() calls from other applications shall fail now */ |
54 | ioctl(d->hPhone, TIOCEXCL, (char *) 0); | 78 | ioctl(d->hPhone, TIOCEXCL, (char *) 0); |
55 | #endif | 79 | #endif |
56 | 80 | ||
57 | if (tcgetattr(d->hPhone, &d->old_settings) == -1) { | 81 | if (tcgetattr(d->hPhone, &d->old_settings) == -1) { |
58 | close(d->hPhone); | 82 | close(d->hPhone); |
59 | GSM_OSErrorInfo(s,"tcgetattr in serial_open"); | 83 | GSM_OSErrorInfo(s,"tcgetattr in serial_open"); |
60 | return ERR_DEVICEREADERROR; | 84 | return ERR_DEVICEREADERROR; |
61 | } | 85 | } |
62 | 86 | ||
63 | if (tcflush(d->hPhone, TCIOFLUSH) == -1) { | 87 | if (tcflush(d->hPhone, TCIOFLUSH) == -1) { |
64 | serial_close(s); | 88 | serial_close(s); |
65 | GSM_OSErrorInfo(s,"tcflush in serial_open"); | 89 | GSM_OSErrorInfo(s,"tcflush in serial_open"); |
66 | return ERR_DEVICEOPENERROR; | 90 | return ERR_DEVICEOPENERROR; |
67 | } | 91 | } |
68 | 92 | ||
69 | memcpy(&t, &d->old_settings, sizeof(struct termios)); | 93 | memcpy(&t, &d->old_settings, sizeof(struct termios)); |
70 | 94 | ||
71 | /* Opening without parity */ | 95 | /* Opening without parity */ |
72 | t.c_iflag = IGNPAR; | 96 | t.c_iflag = IGNPAR; |
73 | t.c_oflag = 0; | 97 | t.c_oflag = 0; |
74 | /* disconnect line, 8 bits, enable receiver, | 98 | /* disconnect line, 8 bits, enable receiver, |
75 | * ignore modem lines,lower modem line after disconnect | 99 | * ignore modem lines,lower modem line after disconnect |
76 | */ | 100 | */ |
77 | t.c_cflag = B0 | CS8 | CREAD | CLOCAL | HUPCL; | 101 | t.c_cflag = B0 | CS8 | CREAD | CLOCAL | HUPCL; |
78 | /* enable hardware (RTS/CTS) flow control (NON POSIX) */ | 102 | /* enable hardware (RTS/CTS) flow control (NON POSIX) */ |
79 | /* t.c_cflag |= CRTSCTS; */ | 103 | /* t.c_cflag |= CRTSCTS; */ |
80 | t.c_lflag = 0; | 104 | t.c_lflag = 0; |
81 | t.c_cc[VMIN] = 1; | 105 | t.c_cc[VMIN] = 1; |
82 | t.c_cc[VTIME] = 0; | 106 | t.c_cc[VTIME] = 0; |
83 | 107 | ||
@@ -132,136 +156,140 @@ static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts) | |||
132 | if (tcgetattr(d->hPhone, &t)) { | 156 | if (tcgetattr(d->hPhone, &t)) { |
133 | GSM_OSErrorInfo(s,"tcgetattr in serial_setdtrrts"); | 157 | GSM_OSErrorInfo(s,"tcgetattr in serial_setdtrrts"); |
134 | return ERR_DEVICEREADERROR; | 158 | return ERR_DEVICEREADERROR; |
135 | } | 159 | } |
136 | 160 | ||
137 | #ifdef CRTSCTS | 161 | #ifdef CRTSCTS |
138 | /* Disabling hardware flow control */ | 162 | /* Disabling hardware flow control */ |
139 | t.c_cflag &= ~CRTSCTS; | 163 | t.c_cflag &= ~CRTSCTS; |
140 | #endif | 164 | #endif |
141 | 165 | ||
142 | if (tcsetattr(d->hPhone, TCSANOW, &t) == -1) { | 166 | if (tcsetattr(d->hPhone, TCSANOW, &t) == -1) { |
143 | serial_close(s); | 167 | serial_close(s); |
144 | GSM_OSErrorInfo(s,"tcsetattr in serial_setdtrrts"); | 168 | GSM_OSErrorInfo(s,"tcsetattr in serial_setdtrrts"); |
145 | return ERR_DEVICEDTRRTSERROR; | 169 | return ERR_DEVICEDTRRTSERROR; |
146 | } | 170 | } |
147 | 171 | ||
148 | flags = TIOCM_DTR; | 172 | flags = TIOCM_DTR; |
149 | if (dtr) { | 173 | if (dtr) { |
150 | ioctl(d->hPhone, TIOCMBIS, &flags); | 174 | ioctl(d->hPhone, TIOCMBIS, &flags); |
151 | } else { | 175 | } else { |
152 | ioctl(d->hPhone, TIOCMBIC, &flags); | 176 | ioctl(d->hPhone, TIOCMBIC, &flags); |
153 | } | 177 | } |
154 | 178 | ||
155 | flags = TIOCM_RTS; | 179 | flags = TIOCM_RTS; |
156 | if (rts) { | 180 | if (rts) { |
157 | ioctl(d->hPhone, TIOCMBIS, &flags); | 181 | ioctl(d->hPhone, TIOCMBIS, &flags); |
158 | } else { | 182 | } else { |
159 | ioctl(d->hPhone, TIOCMBIC, &flags); | 183 | ioctl(d->hPhone, TIOCMBIC, &flags); |
160 | } | 184 | } |
161 | 185 | ||
162 | flags = 0; | 186 | flags = 0; |
163 | ioctl(d->hPhone, TIOCMGET, &flags); | 187 | ioctl(d->hPhone, TIOCMGET, &flags); |
164 | 188 | ||
165 | dbgprintf("Serial device:"); | 189 | dbgprintf("Serial device:"); |
166 | dbgprintf(" DTR is %s", flags&TIOCM_DTR?"up":"down"); | 190 | dbgprintf(" DTR is %s", flags&TIOCM_DTR?"up":"down"); |
167 | dbgprintf(", RTS is %s", flags&TIOCM_RTS?"up":"down"); | 191 | dbgprintf(", RTS is %s", flags&TIOCM_RTS?"up":"down"); |
168 | dbgprintf(", CAR is %s", flags&TIOCM_CAR?"up":"down"); | 192 | dbgprintf(", CAR is %s", flags&TIOCM_CAR?"up":"down"); |
169 | dbgprintf(", CTS is %s\n", flags&TIOCM_CTS?"up":"down"); | 193 | dbgprintf(", CTS is %s\n", flags&TIOCM_CTS?"up":"down"); |
170 | if (((flags&TIOCM_DTR)==TIOCM_DTR) != dtr) return ERR_DEVICEDTRRTSERROR; | 194 | if (((flags&TIOCM_DTR)==TIOCM_DTR) != dtr) return ERR_DEVICEDTRRTSERROR; |
171 | if (((flags&TIOCM_RTS)==TIOCM_RTS) != rts) return ERR_DEVICEDTRRTSERROR; | 195 | if (((flags&TIOCM_RTS)==TIOCM_RTS) != rts) return ERR_DEVICEDTRRTSERROR; |
172 | 196 | ||
173 | return ERR_NONE; | 197 | return ERR_NONE; |
174 | } | 198 | } |
175 | 199 | ||
176 | static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed) | 200 | static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed) |
177 | { | 201 | { |
178 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 202 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
179 | struct termios t; | 203 | struct termios t; |
180 | int speed2 = B19200; | 204 | int speed2 = B19200; |
181 | 205 | ||
182 | if (tcgetattr(d->hPhone, &t)) { | 206 | if (tcgetattr(d->hPhone, &t)) { |
183 | GSM_OSErrorInfo(s,"tcgetattr in serial_setspeed"); | 207 | GSM_OSErrorInfo(s,"tcgetattr in serial_setspeed"); |
184 | return ERR_DEVICEREADERROR; | 208 | return ERR_DEVICEREADERROR; |
185 | } | 209 | } |
186 | 210 | ||
187 | smprintf(s, "Setting speed to %d\n", speed); | 211 | smprintf(s, "Setting speed to %d\n", speed); |
188 | 212 | ||
189 | switch (speed) { | 213 | switch (speed) { |
190 | case 50: speed2 = B50; break; | 214 | case 50: speed2 = B50; break; |
191 | case 75: speed2 = B75; break; | 215 | case 75: speed2 = B75; break; |
192 | case 110: speed2 = B110; break; | 216 | case 110: speed2 = B110; break; |
193 | case 134: speed2 = B134; break; | 217 | case 134: speed2 = B134; break; |
194 | case 150: speed2 = B150; break; | 218 | case 150: speed2 = B150; break; |
195 | case 200: speed2 = B200; break; | 219 | case 200: speed2 = B200; break; |
196 | case 300: speed2 = B300; break; | 220 | case 300: speed2 = B300; break; |
197 | case 600: speed2 = B600; break; | 221 | case 600: speed2 = B600; break; |
198 | case 1200: speed2 = B1200; break; | 222 | case 1200: speed2 = B1200; break; |
199 | case 1800: speed2 = B1800; break; | 223 | case 1800: speed2 = B1800; break; |
200 | case 2400: speed2 = B2400; break; | 224 | case 2400: speed2 = B2400; break; |
201 | case 4800: speed2 = B4800; break; | 225 | case 4800: speed2 = B4800; break; |
202 | case 9600: speed2 = B9600; break; | 226 | case 9600: speed2 = B9600; break; |
203 | case 19200: speed2 = B19200;break; | 227 | case 19200: speed2 = B19200;break; |
204 | case 38400: speed2 = B38400;break; | 228 | case 38400: speed2 = B38400;break; |
229 | #ifdef B57600 | ||
205 | case 57600: speed2 = B57600;break; | 230 | case 57600: speed2 = B57600;break; |
206 | case 115200: speed2 = B115200;break; | 231 | case 115200: speed2 = B115200;break; |
207 | case 230400: speed2 = B230400;break; | 232 | case 230400: speed2 = B230400;break; |
208 | case 460800: speed2 = B460800;break; | 233 | case 460800: speed2 = B460800;break; |
234 | #ifdef B500000 | ||
209 | case 500000: speed2 = B500000;break; | 235 | case 500000: speed2 = B500000;break; |
210 | case 576000: speed2 = B576000;break; | 236 | case 576000: speed2 = B576000;break; |
211 | case 921600: speed2 = B921600;break; | 237 | case 921600: speed2 = B921600;break; |
212 | case 1000000: speed2 = B1000000;break; | 238 | case 1000000: speed2 = B1000000;break; |
213 | case 1152000: speed2 = B1152000;break; | 239 | case 1152000: speed2 = B1152000;break; |
214 | case 1500000: speed2 = B1500000;break; | 240 | case 1500000: speed2 = B1500000;break; |
215 | case 2000000: speed2 = B2000000;break; | 241 | case 2000000: speed2 = B2000000;break; |
216 | case 2500000: speed2 = B2500000;break; | 242 | case 2500000: speed2 = B2500000;break; |
217 | case 3000000: speed2 = B3000000;break; | 243 | case 3000000: speed2 = B3000000;break; |
218 | case 3500000: speed2 = B3500000;break; | 244 | case 3500000: speed2 = B3500000;break; |
219 | case 4000000: speed2 = B4000000; break; | 245 | case 4000000: speed2 = B4000000; break; |
246 | #endif | ||
247 | #endif | ||
220 | } | 248 | } |
221 | 249 | ||
222 | /* This should work on all systems because it is done according to POSIX */ | 250 | /* This should work on all systems because it is done according to POSIX */ |
223 | cfsetispeed(&t, speed2); | 251 | cfsetispeed(&t, speed2); |
224 | cfsetospeed(&t, speed2); | 252 | cfsetospeed(&t, speed2); |
225 | 253 | ||
226 | if (tcsetattr(d->hPhone, TCSADRAIN, &t) == -1) { | 254 | if (tcsetattr(d->hPhone, TCSADRAIN, &t) == -1) { |
227 | serial_close(s); | 255 | serial_close(s); |
228 | GSM_OSErrorInfo(s,"tcsetattr in serial_setspeed"); | 256 | GSM_OSErrorInfo(s,"tcsetattr in serial_setspeed"); |
229 | return ERR_DEVICECHANGESPEEDERROR; | 257 | return ERR_DEVICECHANGESPEEDERROR; |
230 | } | 258 | } |
231 | 259 | ||
232 | return ERR_NONE; | 260 | return ERR_NONE; |
233 | } | 261 | } |
234 | 262 | ||
235 | static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes) | 263 | static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes) |
236 | { | 264 | { |
237 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 265 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
238 | struct timeval timeout2; | 266 | struct timeval timeout2; |
239 | fd_set readfds; | 267 | fd_set readfds; |
240 | int actual = 0; | 268 | int actual = 0; |
241 | 269 | ||
242 | FD_ZERO(&readfds); | 270 | FD_ZERO(&readfds); |
243 | FD_SET(d->hPhone, &readfds); | 271 | FD_SET(d->hPhone, &readfds); |
244 | 272 | ||
245 | timeout2.tv_sec = 0; | 273 | timeout2.tv_sec = 0; |
246 | timeout2.tv_usec = 1; | 274 | timeout2.tv_usec = 1; |
247 | 275 | ||
248 | if (select(d->hPhone+1, &readfds, NULL, NULL, &timeout2)) { | 276 | if (select(d->hPhone+1, &readfds, NULL, NULL, &timeout2)) { |
249 | actual = read(d->hPhone, buf, nbytes); | 277 | actual = read(d->hPhone, buf, nbytes); |
250 | if (actual == -1) GSM_OSErrorInfo(s,"serial_read"); | 278 | if (actual == -1) GSM_OSErrorInfo(s,"serial_read"); |
251 | } | 279 | } |
252 | return actual; | 280 | return actual; |
253 | } | 281 | } |
254 | 282 | ||
255 | static int serial_write(GSM_StateMachine *s, void *buf, size_t nbytes) | 283 | static int serial_write(GSM_StateMachine *s, void *buf, size_t nbytes) |
256 | { | 284 | { |
257 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 285 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
258 | int ret; | 286 | int ret; |
259 | size_t actual = 0; | 287 | size_t actual = 0; |
260 | 288 | ||
261 | do { | 289 | do { |
262 | ret = write(d->hPhone, (unsigned char *)buf, nbytes - actual); | 290 | ret = write(d->hPhone, (unsigned char *)buf, nbytes - actual); |
263 | if (ret < 0 && errno == EAGAIN) continue; | 291 | if (ret < 0 && errno == EAGAIN) continue; |
264 | if (ret < 0) { | 292 | if (ret < 0) { |
265 | if (actual != nbytes) GSM_OSErrorInfo(s,"serial_write"); | 293 | if (actual != nbytes) GSM_OSErrorInfo(s,"serial_write"); |
266 | return actual; | 294 | return actual; |
267 | } | 295 | } |
diff --git a/gammu/emb/common/device/serial/ser_w32.c b/gammu/emb/common/device/serial/ser_w32.c index 9fa0135..7d88fc7 100644 --- a/gammu/emb/common/device/serial/ser_w32.c +++ b/gammu/emb/common/device/serial/ser_w32.c | |||
@@ -1,50 +1,54 @@ | |||
1 | /* (c) 2002-2004 by Marcin Wiacek */ | 1 | /* (c) 2002-2004 by Marcin Wiacek */ |
2 | /* based on some work from Gnokii, MSDN and others */ | 2 | /* based on some work from MSDN and others */ |
3 | /* based on some work from Gnokii (www.gnokii.org) | ||
4 | * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot | ||
5 | * GNU GPL version 2 or later | ||
6 | */ | ||
3 | 7 | ||
4 | #include "../../gsmstate.h" | 8 | #include "../../gsmstate.h" |
5 | 9 | ||
6 | #ifdef GSM_ENABLE_SERIALDEVICE | 10 | #ifdef GSM_ENABLE_SERIALDEVICE |
7 | #ifdef WIN32 | 11 | #ifdef WIN32 |
8 | 12 | ||
9 | #include <windows.h> | 13 | #include <windows.h> |
10 | #include <string.h> | 14 | #include <string.h> |
11 | #include <stdio.h> | 15 | #include <stdio.h> |
12 | #include <io.h> | 16 | #include <io.h> |
13 | #include <memory.h> | 17 | #include <memory.h> |
14 | 18 | ||
15 | #include "../../gsmcomon.h" | 19 | #include "../../gsmcomon.h" |
16 | #include "ser_w32.h" | 20 | #include "ser_w32.h" |
17 | 21 | ||
18 | static GSM_Error serial_close(GSM_StateMachine *s) | 22 | static GSM_Error serial_close(GSM_StateMachine *s) |
19 | { | 23 | { |
20 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 24 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
21 | 25 | ||
22 | /* Disables all monitored events for device */ | 26 | /* Disables all monitored events for device */ |
23 | SetCommMask(d->hPhone, 0); | 27 | SetCommMask(d->hPhone, 0); |
24 | 28 | ||
25 | /* Discards all characters from input/output buffer and terminates | 29 | /* Discards all characters from input/output buffer and terminates |
26 | * pending read/write operations | 30 | * pending read/write operations |
27 | */ | 31 | */ |
28 | PurgeComm(d->hPhone, PURGE_TXABORT | PURGE_RXABORT | | 32 | PurgeComm(d->hPhone, PURGE_TXABORT | PURGE_RXABORT | |
29 | PURGE_TXCLEAR | PURGE_RXCLEAR); | 33 | PURGE_TXCLEAR | PURGE_RXCLEAR); |
30 | 34 | ||
31 | /* Clears the DTR (data-terminal-ready) signal */ | 35 | /* Clears the DTR (data-terminal-ready) signal */ |
32 | EscapeCommFunction(d->hPhone, CLRDTR); | 36 | EscapeCommFunction(d->hPhone, CLRDTR); |
33 | 37 | ||
34 | /* Restores old settings */ | 38 | /* Restores old settings */ |
35 | if (SetCommState(d->hPhone, &d->old_settings)==0) { | 39 | if (SetCommState(d->hPhone, &d->old_settings)==0) { |
36 | GSM_OSErrorInfo(s, "SetCommState in serial_close"); | 40 | GSM_OSErrorInfo(s, "SetCommState in serial_close"); |
37 | } | 41 | } |
38 | 42 | ||
39 | /* Closes device */ | 43 | /* Closes device */ |
40 | if (CloseHandle(d->hPhone)==0) { | 44 | if (CloseHandle(d->hPhone)==0) { |
41 | GSM_OSErrorInfo(s, "CloseHandle in serial_close"); | 45 | GSM_OSErrorInfo(s, "CloseHandle in serial_close"); |
42 | } | 46 | } |
43 | 47 | ||
44 | return ERR_NONE; | 48 | return ERR_NONE; |
45 | } | 49 | } |
46 | 50 | ||
47 | static GSM_Error serial_open (GSM_StateMachine *s) | 51 | static GSM_Error serial_open (GSM_StateMachine *s) |
48 | { | 52 | { |
49 | GSM_Device_SerialData *d = &s->Device.Data.Serial; | 53 | GSM_Device_SerialData *d = &s->Device.Data.Serial; |
50 | DCB dcb; | 54 | DCB dcb; |