author | zautrix <zautrix> | 2004-08-07 17:24:40 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-08-07 17:24:40 (UTC) |
commit | 88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22 (patch) (unidiff) | |
tree | 6331418973714243beb674abc87692277b83869d /gammu/emb/common/protocol/nokia | |
parent | ef8a09ce74ad3f0a51484d03fdf009bd5b3677bf (diff) | |
download | kdepimpi-88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22.zip kdepimpi-88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22.tar.gz kdepimpi-88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22.tar.bz2 |
Initial revision
Diffstat (limited to 'gammu/emb/common/protocol/nokia') (more/less context) (ignore whitespace changes)
-rw-r--r-- | gammu/emb/common/protocol/nokia/fbus2.c | 444 | ||||
-rw-r--r-- | gammu/emb/common/protocol/nokia/fbus2.h | 38 | ||||
-rw-r--r-- | gammu/emb/common/protocol/nokia/mbus2.c | 252 | ||||
-rw-r--r-- | gammu/emb/common/protocol/nokia/mbus2.h | 28 | ||||
-rw-r--r-- | gammu/emb/common/protocol/nokia/phonet.c | 217 | ||||
-rw-r--r-- | gammu/emb/common/protocol/nokia/phonet.h | 35 |
6 files changed, 1014 insertions, 0 deletions
diff --git a/gammu/emb/common/protocol/nokia/fbus2.c b/gammu/emb/common/protocol/nokia/fbus2.c new file mode 100644 index 0000000..8b3e024 --- a/dev/null +++ b/gammu/emb/common/protocol/nokia/fbus2.c | |||
@@ -0,0 +1,444 @@ | |||
1 | /* (c) 2002-2003 by Marcin Wiacek */ | ||
2 | /* based on some work from Gnokii and MyGnokii */ | ||
3 | |||
4 | #include "../../gsmstate.h" | ||
5 | |||
6 | #if defined(GSM_ENABLE_FBUS2) || defined(GSM_ENABLE_FBUS2IRDA) || defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_FBUS2BLUE) || defined(GSM_ENABLE_BLUEFBUS2) || defined(GSM_ENABLE_FBUS2DKU5) || defined(GSM_ENABLE_FBUS2PL2303) | ||
7 | |||
8 | #include <stdio.h> | ||
9 | #include <string.h> | ||
10 | |||
11 | #include "../../gsmcomon.h" | ||
12 | #include "fbus2.h" | ||
13 | |||
14 | static GSM_Error FBUS2_WriteFrame(GSM_StateMachine *s, | ||
15 | unsigned char *MsgBuffer, | ||
16 | int MsgLength, | ||
17 | unsigned char MsgType) | ||
18 | { | ||
19 | unsigned char buffer2[FBUS2_MAX_TRANSMIT_LENGTH + 10]; | ||
20 | unsigned char checksum=0; | ||
21 | int i, len, sent; | ||
22 | |||
23 | buffer2[0] = FBUS2_FRAME_ID; | ||
24 | if (s->ConnectionType==GCT_FBUS2IRDA) buffer2[0] = FBUS2_IRDA_FRAME_ID; | ||
25 | |||
26 | buffer2[1] = FBUS2_DEVICE_PHONE; //destination | ||
27 | buffer2[2] = FBUS2_DEVICE_PC; //source | ||
28 | buffer2[3]= MsgType; | ||
29 | buffer2[4]= MsgLength / 256; | ||
30 | buffer2[5]= MsgLength % 256; | ||
31 | |||
32 | memcpy(buffer2 + 6, MsgBuffer, MsgLength); | ||
33 | len = MsgLength + 6; | ||
34 | |||
35 | /* Odd messages require additional 0x00 byte */ | ||
36 | if (MsgLength % 2) buffer2[len++] = 0x00; | ||
37 | |||
38 | checksum = 0; | ||
39 | for (i = 0; i < len; i+=2) checksum ^= buffer2[i]; | ||
40 | buffer2[len++] = checksum; | ||
41 | |||
42 | checksum = 0; | ||
43 | for (i = 1; i < len; i+=2) checksum ^= buffer2[i]; | ||
44 | buffer2[len++] = checksum; | ||
45 | |||
46 | /* Sending to phone */ | ||
47 | sent=s->Device.Functions->WriteDevice(s,buffer2,len); | ||
48 | if (sent!=len) return ERR_DEVICEWRITEERROR; | ||
49 | |||
50 | return ERR_NONE; | ||
51 | } | ||
52 | |||
53 | static GSM_Error FBUS2_WriteMessage (GSM_StateMachine *s, | ||
54 | unsigned char *MsgBuffer, | ||
55 | int MsgLength, | ||
56 | unsigned char MsgType) | ||
57 | { | ||
58 | int i, nom, togo, thislength; /* number of messages, ... */ | ||
59 | unsigned char buffer2[FBUS2_MAX_TRANSMIT_LENGTH + 2], seqnum; | ||
60 | GSM_Protocol_FBUS2Data*d = &s->Protocol.Data.FBUS2; | ||
61 | GSM_Error error; | ||
62 | |||
63 | GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType); | ||
64 | |||
65 | nom = (MsgLength + FBUS2_MAX_TRANSMIT_LENGTH - 1) / FBUS2_MAX_TRANSMIT_LENGTH; | ||
66 | togo = MsgLength; | ||
67 | |||
68 | for (i = 0; i < nom; i++) { | ||
69 | seqnum = d->MsgSequenceNumber; | ||
70 | if (i==0) seqnum = seqnum + 0x40; | ||
71 | d->MsgSequenceNumber = (d->MsgSequenceNumber + 1) & 0x07; | ||
72 | |||
73 | thislength = togo; | ||
74 | if (togo > FBUS2_MAX_TRANSMIT_LENGTH) thislength = FBUS2_MAX_TRANSMIT_LENGTH; | ||
75 | memcpy(buffer2, MsgBuffer + (MsgLength - togo), thislength); | ||
76 | buffer2[thislength]= nom - i; | ||
77 | buffer2[thislength + 1]= seqnum; | ||
78 | togo = togo - thislength; | ||
79 | |||
80 | GSM_DumpMessageLevel2(s, buffer2, thislength, MsgType); | ||
81 | |||
82 | error=FBUS2_WriteFrame(s, buffer2, thislength + 2, MsgType); | ||
83 | if (error!=ERR_NONE) return error; | ||
84 | } | ||
85 | |||
86 | return ERR_NONE; | ||
87 | } | ||
88 | |||
89 | static GSM_Error FBUS2_SendAck(GSM_StateMachine *s, | ||
90 | unsigned char MsgType, | ||
91 | unsigned char MsgSequence) | ||
92 | { | ||
93 | unsigned char buffer2[2]; | ||
94 | |||
95 | buffer2[0] = MsgType; | ||
96 | buffer2[1] = MsgSequence; | ||
97 | |||
98 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || | ||
99 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { | ||
100 | smprintf(s,"[Sending Ack of type %02x, seq %x]\n",buffer2[0],buffer2[1]); | ||
101 | } | ||
102 | |||
103 | /* Sending to phone */ | ||
104 | return FBUS2_WriteFrame(s, buffer2, 2, FBUS2_ACK_BYTE); | ||
105 | } | ||
106 | |||
107 | static GSM_Error FBUS2_StateMachine(GSM_StateMachine *s, unsigned char rx_char) | ||
108 | { | ||
109 | GSM_Protocol_FBUS2Data *d = &s->Protocol.Data.FBUS2; | ||
110 | unsigned char frm_num, seq_num; | ||
111 | bool correct = false; | ||
112 | |||
113 | /* XOR the byte with the earlier checksum */ | ||
114 | d->Msg.CheckSum[d->Msg.Count & 1] ^= rx_char; | ||
115 | |||
116 | if (d->MsgRXState == RX_GetMessage) { | ||
117 | d->Msg.Buffer[d->Msg.Count] = rx_char; | ||
118 | d->Msg.Count++; | ||
119 | |||
120 | /* This is not last byte in frame */ | ||
121 | if (d->Msg.Count != d->Msg.Length+(d->Msg.Length%2)+2) return ERR_NONE; | ||
122 | |||
123 | /* Checksum is incorrect */ | ||
124 | if (d->Msg.CheckSum[0] != d->Msg.CheckSum[1]) { | ||
125 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | ||
126 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | ||
127 | smprintf(s,"[ERROR: checksum]\n"); | ||
128 | } | ||
129 | free(d->Msg.Buffer); | ||
130 | d->Msg.Length = 0; | ||
131 | d->Msg.Buffer = NULL; | ||
132 | |||
133 | d->MsgRXState = RX_Sync; | ||
134 | return ERR_NONE; | ||
135 | } | ||
136 | |||
137 | seq_num = d->Msg.Buffer[d->Msg.Length-1]; | ||
138 | |||
139 | if (d->Msg.Type == FBUS2_ACK_BYTE) { | ||
140 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || | ||
141 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { | ||
142 | smprintf(s, "[Received Ack of type %02x, seq %02x]\n",d->Msg.Buffer[0],seq_num); | ||
143 | } | ||
144 | |||
145 | d->MsgRXState = RX_Sync; | ||
146 | return ERR_NONE; | ||
147 | } | ||
148 | |||
149 | frm_num = d->Msg.Buffer[d->Msg.Length-2]; | ||
150 | |||
151 | if ((seq_num & 0x40) == 0x40) { | ||
152 | d->FramesToGo = frm_num; | ||
153 | d->MultiMsg.Length= 0; | ||
154 | d->MultiMsg.Type= d->Msg.Type; | ||
155 | d->MultiMsg.Destination= d->Msg.Destination; | ||
156 | d->MultiMsg.Source= d->Msg.Source; | ||
157 | } | ||
158 | |||
159 | if ((seq_num & 0x40) != 0x40 && d->FramesToGo != frm_num) { | ||
160 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | ||
161 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | ||
162 | smprintf(s, "[ERROR: Missed part of multiframe msg]\n"); | ||
163 | } | ||
164 | |||
165 | free(d->Msg.Buffer); | ||
166 | d->Msg.Length = 0; | ||
167 | d->Msg.Buffer = NULL; | ||
168 | |||
169 | d->MsgRXState = RX_Sync; | ||
170 | return ERR_NONE; | ||
171 | } | ||
172 | |||
173 | if ((seq_num & 0x40) != 0x40 && d->Msg.Type != d->MultiMsg.Type) { | ||
174 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | ||
175 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | ||
176 | smprintf(s, "[ERROR: Multiframe msg in multiframe msg]\n"); | ||
177 | } | ||
178 | |||
179 | free(d->Msg.Buffer); | ||
180 | d->Msg.Length = 0; | ||
181 | d->Msg.Buffer = NULL; | ||
182 | |||
183 | d->MsgRXState = RX_Sync; | ||
184 | return ERR_NONE; | ||
185 | } | ||
186 | |||
187 | if (d->MultiMsg.BufferUsed < d->MultiMsg.Length+d->Msg.Length-2) { | ||
188 | d->MultiMsg.BufferUsed = d->MultiMsg.Length+d->Msg.Length-2; | ||
189 | d->MultiMsg.Buffer = (unsigned char *)realloc(d->MultiMsg.Buffer,d->MultiMsg.BufferUsed); | ||
190 | } | ||
191 | memcpy(d->MultiMsg.Buffer+d->MultiMsg.Length,d->Msg.Buffer,d->Msg.Length-2); | ||
192 | d->MultiMsg.Length = d->MultiMsg.Length+d->Msg.Length-2; | ||
193 | |||
194 | free(d->Msg.Buffer); | ||
195 | d->Msg.Length = 0; | ||
196 | d->Msg.Buffer = NULL; | ||
197 | |||
198 | d->FramesToGo--; | ||
199 | |||
200 | /* do not ack debug trace, as this could generate a | ||
201 | * (feedback loop) flood of which even Noah would be scared. | ||
202 | */ | ||
203 | if (d->Msg.Type != 0) { | ||
204 | FBUS2_SendAck(s,d->Msg.Type,((unsigned char)(seq_num & 0x0f))); | ||
205 | } | ||
206 | |||
207 | if (d->FramesToGo == 0) { | ||
208 | s->Phone.Data.RequestMsg= &d->MultiMsg; | ||
209 | s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); | ||
210 | } | ||
211 | d->MsgRXState = RX_Sync; | ||
212 | return ERR_NONE; | ||
213 | } | ||
214 | if (d->MsgRXState == RX_GetLength2) { | ||
215 | d->Msg.Length = d->Msg.Length + rx_char; | ||
216 | d->Msg.Buffer = (unsigned char *)malloc(d->Msg.Length+3); | ||
217 | d->MsgRXState = RX_GetMessage; | ||
218 | return ERR_NONE; | ||
219 | } | ||
220 | if (d->MsgRXState == RX_GetLength1) { | ||
221 | d->Msg.Length = rx_char * 256; | ||
222 | d->MsgRXState = RX_GetLength2; | ||
223 | return ERR_NONE; | ||
224 | } | ||
225 | if (d->MsgRXState == RX_GetType) { | ||
226 | d->Msg.Type = rx_char; | ||
227 | d->MsgRXState = RX_GetLength1; | ||
228 | return ERR_NONE; | ||
229 | } | ||
230 | if (d->MsgRXState == RX_GetSource) { | ||
231 | if (rx_char != FBUS2_DEVICE_PHONE) { | ||
232 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | ||
233 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | ||
234 | smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, FBUS2_DEVICE_PHONE); | ||
235 | } | ||
236 | |||
237 | d->MsgRXState = RX_Sync; | ||
238 | return ERR_NONE; | ||
239 | } | ||
240 | d->Msg.Source = rx_char; | ||
241 | |||
242 | d->MsgRXState = RX_GetType; | ||
243 | return ERR_NONE; | ||
244 | } | ||
245 | if (d->MsgRXState == RX_GetDestination) { | ||
246 | if (rx_char != FBUS2_DEVICE_PC) { | ||
247 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | ||
248 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | ||
249 | smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, FBUS2_DEVICE_PC); | ||
250 | } | ||
251 | |||
252 | d->MsgRXState = RX_Sync; | ||
253 | return ERR_NONE; | ||
254 | } | ||
255 | d->Msg.Destination = rx_char; | ||
256 | |||
257 | d->MsgRXState = RX_GetSource; | ||
258 | return ERR_NONE; | ||
259 | } | ||
260 | if (d->MsgRXState == RX_Sync) { | ||
261 | switch (s->ConnectionType) { | ||
262 | case GCT_FBUS2: | ||
263 | case GCT_FBUS2DLR3: | ||
264 | case GCT_FBUS2DKU5: | ||
265 | case GCT_FBUS2PL2303: | ||
266 | case GCT_FBUS2BLUE: | ||
267 | case GCT_BLUEFBUS2: | ||
268 | if (rx_char == FBUS2_FRAME_ID) correct = true; | ||
269 | break; | ||
270 | case GCT_FBUS2IRDA: | ||
271 | if (rx_char == FBUS2_IRDA_FRAME_ID) correct = true; | ||
272 | break; | ||
273 | default: | ||
274 | break; | ||
275 | } | ||
276 | if (!correct) { | ||
277 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | ||
278 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | ||
279 | if (s->ConnectionType==GCT_FBUS2IRDA) { | ||
280 | smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, FBUS2_IRDA_FRAME_ID); | ||
281 | } else { | ||
282 | smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, FBUS2_FRAME_ID); | ||
283 | } | ||
284 | } | ||
285 | return ERR_NONE; | ||
286 | } | ||
287 | |||
288 | d->Msg.CheckSum[0] = rx_char; | ||
289 | d->Msg.CheckSum[1] = 0; | ||
290 | d->Msg.Count = 0; | ||
291 | |||
292 | d->MsgRXState = RX_GetDestination; | ||
293 | return ERR_NONE; | ||
294 | } | ||
295 | return ERR_NONE; | ||
296 | } | ||
297 | |||
298 | #if defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_FBUS2DKU5) || defined(GSM_ENABLE_FBUS2BLUE) || defined(GSM_ENABLE_BLUEFBUS2) || defined(GSM_ENABLE_FBUS2PL2303) | ||
299 | static void FBUS2_WriteDLR3(GSM_StateMachine *s, char *command, int length, int timeout) | ||
300 | { | ||
301 | unsigned char buff[300]; | ||
302 | int w = 0; | ||
303 | bool wassomething = false; | ||
304 | |||
305 | s->Device.Functions->WriteDevice(s,command,length); | ||
306 | |||
307 | for (w=0;w<timeout;w++) { | ||
308 | if (wassomething) { | ||
309 | if (s->Device.Functions->ReadDevice(s, buff, 255)==0) return; | ||
310 | } else { | ||
311 | if (s->Device.Functions->ReadDevice(s, buff, 255)>0) wassomething = true; | ||
312 | } | ||
313 | my_sleep(50); | ||
314 | } | ||
315 | } | ||
316 | #endif | ||
317 | |||
318 | static GSM_Error FBUS2_Initialise(GSM_StateMachine *s) | ||
319 | { | ||
320 | unsigned char init_char= 0x55; | ||
321 | #ifdef GSM_ENABLE_FBUS2IRDA | ||
322 | unsigned char end_init_char= 0xc1; | ||
323 | #endif | ||
324 | |||
325 | GSM_Protocol_FBUS2Data *d = &s->Protocol.Data.FBUS2; | ||
326 | GSM_Device_Functions *Device = s->Device.Functions; | ||
327 | GSM_Error error; | ||
328 | int count; | ||
329 | |||
330 | d->Msg.Length = 0; | ||
331 | d->Msg.Buffer = NULL; | ||
332 | d->MultiMsg.BufferUsed= 0; | ||
333 | d->MultiMsg.Length= 0; | ||
334 | d->MultiMsg.Buffer= NULL; | ||
335 | |||
336 | d->MsgSequenceNumber= 0; | ||
337 | d->FramesToGo = 0; | ||
338 | d->MsgRXState = RX_Sync; | ||
339 | |||
340 | error=Device->DeviceSetParity(s,false); | ||
341 | if (error!=ERR_NONE) return error; | ||
342 | |||
343 | switch (s->ConnectionType) { | ||
344 | #if defined(GSM_ENABLE_BLUEFBUS2) || defined(GSM_ENABLE_FBUS2BLUE) | ||
345 | case GCT_FBUS2BLUE: | ||
346 | case GCT_BLUEFBUS2: | ||
347 | FBUS2_WriteDLR3(s,"AT\r\n", 4,10); | ||
348 | FBUS2_WriteDLR3(s,"AT&F\r\n", 6,10); | ||
349 | FBUS2_WriteDLR3(s,"AT*NOKIAFBUS\r\n",14,10); | ||
350 | break; | ||
351 | #endif | ||
352 | #if defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_FBUS2DKU5) || defined(GSM_ENABLE_FBUS2PL2303) | ||
353 | case GCT_FBUS2DKU5: | ||
354 | case GCT_FBUS2PL2303: | ||
355 | case GCT_FBUS2DLR3: | ||
356 | error=Device->DeviceSetDtrRts(s,false,false); | ||
357 | if (error!=ERR_NONE) return error; | ||
358 | my_sleep(1000); | ||
359 | |||
360 | error=Device->DeviceSetDtrRts(s,true,true); | ||
361 | if (error!=ERR_NONE) return error; | ||
362 | error=Device->DeviceSetSpeed(s,19200); | ||
363 | if (error!=ERR_NONE) return error; | ||
364 | |||
365 | FBUS2_WriteDLR3(s,"AT\r\n", 4,10); | ||
366 | FBUS2_WriteDLR3(s,"AT&F\r\n", 6,10); | ||
367 | FBUS2_WriteDLR3(s,"AT*NOKIAFBUS\r\n",14,10); | ||
368 | |||
369 | error=Device->CloseDevice(s); | ||
370 | if (error!=ERR_NONE) return error; | ||
371 | my_sleep(1000); | ||
372 | |||
373 | error=Device->OpenDevice(s); | ||
374 | if (error!=ERR_NONE) return error; | ||
375 | error=Device->DeviceSetParity(s,false); | ||
376 | if (error!=ERR_NONE) return error; | ||
377 | error=Device->DeviceSetSpeed(s,115200); | ||
378 | if (error!=ERR_NONE) return error; | ||
379 | error=Device->DeviceSetDtrRts(s,false,false); | ||
380 | if (error!=ERR_NONE) return error; | ||
381 | |||
382 | for (count = 0; count < 55; count ++) { | ||
383 | if (Device->WriteDevice(s,&init_char,1)!=1) return ERR_DEVICEWRITEERROR; | ||
384 | } | ||
385 | break; | ||
386 | #endif | ||
387 | case GCT_FBUS2: | ||
388 | error=Device->DeviceSetSpeed(s,115200); | ||
389 | if (error!=ERR_NONE) return error; | ||
390 | |||
391 | error=Device->DeviceSetDtrRts(s,true,false); /*DTR high,RTS low*/ | ||
392 | if (error!=ERR_NONE) return error; | ||
393 | |||
394 | for (count = 0; count < 55; count ++) { | ||
395 | if (Device->WriteDevice(s,&init_char,1)!=1) return ERR_DEVICEWRITEERROR; | ||
396 | my_sleep(10); | ||
397 | } | ||
398 | break; | ||
399 | #ifdef GSM_ENABLE_FBUS2IRDA | ||
400 | case GCT_FBUS2IRDA: | ||
401 | error=Device->DeviceSetSpeed(s,9600); | ||
402 | if (error!=ERR_NONE) return error; | ||
403 | |||
404 | for (count = 0; count < 55; count ++) { | ||
405 | if (Device->WriteDevice(s,&init_char,1)!=1) return ERR_DEVICEWRITEERROR; | ||
406 | my_sleep(10); | ||
407 | } | ||
408 | |||
409 | if (Device->WriteDevice(s,&end_init_char,1)!=1) return ERR_DEVICEWRITEERROR; | ||
410 | my_sleep(20); | ||
411 | |||
412 | error=Device->DeviceSetSpeed(s,115200); | ||
413 | if (error!=ERR_NONE) return error; | ||
414 | |||
415 | break; | ||
416 | #endif | ||
417 | default: | ||
418 | break; | ||
419 | } | ||
420 | |||
421 | return ERR_NONE; | ||
422 | } | ||
423 | |||
424 | static GSM_Error FBUS2_Terminate(GSM_StateMachine *s) | ||
425 | { | ||
426 | free(s->Protocol.Data.FBUS2.Msg.Buffer); | ||
427 | free(s->Protocol.Data.FBUS2.MultiMsg.Buffer); | ||
428 | |||
429 | my_sleep(200); | ||
430 | return ERR_NONE; | ||
431 | } | ||
432 | |||
433 | GSM_Protocol_Functions FBUS2Protocol = { | ||
434 | FBUS2_WriteMessage, | ||
435 | FBUS2_StateMachine, | ||
436 | FBUS2_Initialise, | ||
437 | FBUS2_Terminate | ||
438 | }; | ||
439 | |||
440 | #endif | ||
441 | |||
442 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
443 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
444 | */ | ||
diff --git a/gammu/emb/common/protocol/nokia/fbus2.h b/gammu/emb/common/protocol/nokia/fbus2.h new file mode 100644 index 0000000..5dd45d7 --- a/dev/null +++ b/gammu/emb/common/protocol/nokia/fbus2.h | |||
@@ -0,0 +1,38 @@ | |||
1 | /* (c) 2002-2003 by Marcin Wiacek */ | ||
2 | /* based on some work from Gnokii and MyGnokii */ | ||
3 | |||
4 | #ifndef fbus2_h | ||
5 | #define fbus2_h | ||
6 | |||
7 | #include "../protocol.h" | ||
8 | |||
9 | #define FBUS2_FRAME_ID 0x1e | ||
10 | #define FBUS2_IRDA_FRAME_ID 0x1c | ||
11 | #define FBUS2_DEVICE_PHONE 0x00 /* Nokia mobile phone */ | ||
12 | #define FBUS2_DEVICE_PC 0x0c /* Our PC */ | ||
13 | #define FBUS2_ACK_BYTE 0x7f /* Acknowledge of the received frame */ | ||
14 | |||
15 | #define FBUS2_MAX_TRANSMIT_LENGTH 120 | ||
16 | |||
17 | typedef struct { | ||
18 | int MsgSequenceNumber; | ||
19 | int MsgRXState; | ||
20 | int FramesToGo; | ||
21 | GSM_Protocol_MessageMultiMsg; | ||
22 | GSM_Protocol_MessageMsg; | ||
23 | } GSM_Protocol_FBUS2Data; | ||
24 | |||
25 | #ifndef GSM_USED_SERIALDEVICE | ||
26 | # define GSM_USED_SERIALDEVICE | ||
27 | #endif | ||
28 | #if defined(GSM_ENABLE_BLUEFBUS2) | ||
29 | # ifndef GSM_USED_BLUETOOTHDEVICE | ||
30 | # define GSM_USED_BLUETOOTHDEVICE | ||
31 | # endif | ||
32 | #endif | ||
33 | |||
34 | #endif | ||
35 | |||
36 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
37 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
38 | */ | ||
diff --git a/gammu/emb/common/protocol/nokia/mbus2.c b/gammu/emb/common/protocol/nokia/mbus2.c new file mode 100644 index 0000000..f07d6c5 --- a/dev/null +++ b/gammu/emb/common/protocol/nokia/mbus2.c | |||
@@ -0,0 +1,252 @@ | |||
1 | /* (c) 2001-2003 by Marcin Wiacek */ | ||
2 | /* based on some work from MyGnokii */ | ||
3 | |||
4 | #include "../../gsmstate.h" | ||
5 | |||
6 | #ifdef GSM_ENABLE_MBUS2 | ||
7 | |||
8 | #include <stdio.h> | ||
9 | #include <string.h> | ||
10 | |||
11 | #include "../../gsmcomon.h" | ||
12 | #include "mbus2.h" | ||
13 | |||
14 | static GSM_Error MBUS2_WriteMessage (GSM_StateMachine *s, | ||
15 | unsigned char *MsgBuffer, | ||
16 | int MsgLength, | ||
17 | unsigned char MsgType) | ||
18 | { | ||
19 | unsigned char *buffer2, checksum = 0; | ||
20 | GSM_Protocol_MBUS2Data *d = &s->Protocol.Data.MBUS2; | ||
21 | int i, sent, len; | ||
22 | |||
23 | GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType); | ||
24 | |||
25 | buffer2 = (unsigned char *)malloc(MsgLength + 8); | ||
26 | |||
27 | buffer2[0] = MBUS2_FRAME_ID; | ||
28 | buffer2[1] = MBUS2_DEVICE_PHONE; // destination | ||
29 | buffer2[2] = MBUS2_DEVICE_PC; // source | ||
30 | buffer2[3] = MsgType; | ||
31 | buffer2[4] = MsgLength / 256; | ||
32 | buffer2[5] = MsgLength % 256; | ||
33 | |||
34 | memcpy(buffer2 + 6, MsgBuffer, MsgLength); | ||
35 | len = 6 + MsgLength; | ||
36 | |||
37 | /* According to http://www.flosys.com/tdma/n5160.html some phones | ||
38 | * can have problems with checksum equal 0x1F. Phones can recognize | ||
39 | * received frame, but won't send ACK for it. When checksum is 0x1F, | ||
40 | * we increment the sequence number | ||
41 | */ | ||
42 | do { | ||
43 | d->MsgSequenceNumber++; | ||
44 | |||
45 | buffer2[len] = d->MsgSequenceNumber; | ||
46 | |||
47 | /* Calculating checksum */ | ||
48 | checksum = 0; | ||
49 | for (i = 0; i < len + 1; i++) checksum ^= buffer2[i]; | ||
50 | } while (checksum == 0x1f); | ||
51 | |||
52 | buffer2[len++] = d->MsgSequenceNumber; | ||
53 | buffer2[len++] = checksum; | ||
54 | |||
55 | GSM_DumpMessageLevel2(s, buffer2+6, MsgLength, MsgType); | ||
56 | |||
57 | /* Sending to phone */ | ||
58 | my_sleep(10); | ||
59 | sent=s->Device.Functions->WriteDevice(s,buffer2,len); | ||
60 | |||
61 | free(buffer2); | ||
62 | |||
63 | if (sent!=len) return ERR_DEVICEWRITEERROR; | ||
64 | return ERR_NONE; | ||
65 | } | ||
66 | |||
67 | static GSM_Error MBUS2_SendAck(GSM_StateMachine *s, | ||
68 | unsigned char type, | ||
69 | unsigned char sequence) | ||
70 | { | ||
71 | GSM_Device_Functions *Device = s->Device.Functions; | ||
72 | unsigned char buffer2[6]; | ||
73 | int i; | ||
74 | |||
75 | buffer2[0] = MBUS2_FRAME_ID; | ||
76 | buffer2[1] = MBUS2_DEVICE_PHONE;//destination | ||
77 | buffer2[2] = MBUS2_DEVICE_PC; //source | ||
78 | buffer2[3] = MBUS2_ACK_BYTE; | ||
79 | buffer2[4] = sequence; | ||
80 | buffer2[5] = 0; | ||
81 | |||
82 | /* Calculating checksum */ | ||
83 | for (i = 0; i < 5; i++) buffer2[5] ^= buffer2[i]; | ||
84 | |||
85 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || | ||
86 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { | ||
87 | smprintf(s,"[Sending Ack of type %02x, seq: %x]\n",type,sequence); | ||
88 | } | ||
89 | |||
90 | /* Sending to phone */ | ||
91 | my_sleep(10); | ||
92 | if (Device->WriteDevice(s,buffer2,6)!=6) return ERR_DEVICEWRITEERROR; | ||
93 | |||
94 | return ERR_NONE; | ||
95 | } | ||
96 | |||
97 | static GSM_Error MBUS2_StateMachine(GSM_StateMachine *s, unsigned char rx_char) | ||
98 | { | ||
99 | GSM_Phone_Functions *Phone= s->Phone.Functions; | ||
100 | GSM_Protocol_MBUS2Data *d= &s->Protocol.Data.MBUS2; | ||
101 | |||
102 | d->Msg.CheckSum[0] = d->Msg.CheckSum[1]; | ||
103 | d->Msg.CheckSum[1] ^= rx_char; | ||
104 | |||
105 | if (d->MsgRXState == RX_GetMessage) { | ||
106 | d->Msg.Buffer[d->Msg.Count] = rx_char; | ||
107 | d->Msg.Count++; | ||
108 | |||
109 | /* This is not last byte in frame */ | ||
110 | if (d->Msg.Count != d->Msg.Length+2) return ERR_NONE; | ||
111 | |||
112 | /* Checksum is incorrect */ | ||
113 | if (d->Msg.CheckSum[0] != rx_char) { | ||
114 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | ||
115 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | ||
116 | smprintf(s,"[ERROR: checksum]\n"); | ||
117 | } | ||
118 | |||
119 | d->MsgRXState = RX_Sync; | ||
120 | return ERR_NONE; | ||
121 | } | ||
122 | |||
123 | if (d->Msg.Destination != MBUS2_DEVICE_PHONE) { | ||
124 | MBUS2_SendAck(s, d->Msg.Type, d->Msg.Buffer[d->Msg.Count-2]); | ||
125 | s->Phone.Data.RequestMsg= &d->Msg; | ||
126 | s->Phone.Data.DispatchError= Phone->DispatchMessage(s); | ||
127 | } | ||
128 | |||
129 | d->MsgRXState = RX_Sync; | ||
130 | return ERR_NONE; | ||
131 | } | ||
132 | if (d->MsgRXState == RX_GetLength2) { | ||
133 | if (d->Msg.Type == MBUS2_ACK_BYTE) { | ||
134 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || | ||
135 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { | ||
136 | smprintf(s,"[Received Ack]\n"); | ||
137 | } | ||
138 | |||
139 | d->MsgRXState = RX_Sync; | ||
140 | return ERR_NONE; | ||
141 | } | ||
142 | |||
143 | d->Msg.Length = d->Msg.Length + rx_char; | ||
144 | if (d->Msg.BufferUsed < d->Msg.Length+2) { | ||
145 | d->Msg.BufferUsed = d->Msg.Length+2; | ||
146 | d->Msg.Buffer = (unsigned char *)realloc(d->Msg.Buffer,d->Msg.BufferUsed); | ||
147 | } | ||
148 | |||
149 | d->MsgRXState = RX_GetMessage; | ||
150 | return ERR_NONE; | ||
151 | } | ||
152 | if (d->MsgRXState == RX_GetLength1) { | ||
153 | d->Msg.Length = rx_char * 256; | ||
154 | |||
155 | d->MsgRXState = RX_GetLength2; | ||
156 | return ERR_NONE; | ||
157 | } | ||
158 | if (d->MsgRXState == RX_GetType) { | ||
159 | d->Msg.Type = rx_char; | ||
160 | |||
161 | d->MsgRXState = RX_GetLength1; | ||
162 | return ERR_NONE; | ||
163 | } | ||
164 | if (d->MsgRXState == RX_GetSource) { | ||
165 | if (rx_char != MBUS2_DEVICE_PHONE && rx_char != MBUS2_DEVICE_PC) { | ||
166 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | ||
167 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | ||
168 | smprintf(s,"[ERROR: incorrect char - %02x, not %02x and %02x]\n", rx_char, MBUS2_DEVICE_PHONE, MBUS2_DEVICE_PC); | ||
169 | } | ||
170 | d->MsgRXState = RX_Sync; | ||
171 | return ERR_NONE; | ||
172 | } | ||
173 | d->Msg.Source = rx_char; | ||
174 | |||
175 | d->MsgRXState = RX_GetType; | ||
176 | return ERR_NONE; | ||
177 | } | ||
178 | if (d->MsgRXState == RX_GetDestination) { | ||
179 | if (rx_char != MBUS2_DEVICE_PC && rx_char != MBUS2_DEVICE_PHONE) { | ||
180 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | ||
181 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | ||
182 | smprintf(s,"[ERROR: incorrect char - %02x, not %02x and %02x]\n", rx_char, MBUS2_DEVICE_PHONE, MBUS2_DEVICE_PC); | ||
183 | } | ||
184 | d->MsgRXState = RX_Sync; | ||
185 | return ERR_NONE; | ||
186 | } | ||
187 | d->Msg.Destination = rx_char; | ||
188 | |||
189 | d->MsgRXState = RX_GetSource; | ||
190 | return ERR_NONE; | ||
191 | } | ||
192 | if (d->MsgRXState == RX_Sync) { | ||
193 | if (rx_char != MBUS2_FRAME_ID) { | ||
194 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | ||
195 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | ||
196 | smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, MBUS2_FRAME_ID); | ||
197 | } | ||
198 | return ERR_NONE; | ||
199 | } | ||
200 | d->Msg.CheckSum[1] = MBUS2_FRAME_ID; | ||
201 | d->Msg.Count = 0; | ||
202 | |||
203 | d->MsgRXState = RX_GetDestination; | ||
204 | return ERR_NONE; | ||
205 | } | ||
206 | return ERR_NONE; | ||
207 | } | ||
208 | |||
209 | static GSM_Error MBUS2_Initialise(GSM_StateMachine *s) | ||
210 | { | ||
211 | GSM_Device_Functions *Device= s->Device.Functions; | ||
212 | GSM_Protocol_MBUS2Data *d= &s->Protocol.Data.MBUS2; | ||
213 | GSM_Error error; | ||
214 | |||
215 | d->Msg.Length = 0; | ||
216 | d->Msg.BufferUsed= 0; | ||
217 | d->Msg.Buffer = NULL; | ||
218 | |||
219 | d->MsgSequenceNumber= 0; | ||
220 | d->MsgRXState = RX_Sync; | ||
221 | |||
222 | error=Device->DeviceSetSpeed(s,9600); | ||
223 | if (error!=ERR_NONE) return error; | ||
224 | |||
225 | error=Device->DeviceSetParity(s,true); | ||
226 | if (error!=ERR_NONE) return error; | ||
227 | |||
228 | error=Device->DeviceSetDtrRts(s,false,true); /*DTR low,RTS high*/ | ||
229 | if (error!=ERR_NONE) return error; | ||
230 | my_sleep(200); | ||
231 | |||
232 | return ERR_NONE; | ||
233 | } | ||
234 | |||
235 | static GSM_Error MBUS2_Terminate(GSM_StateMachine *s) | ||
236 | { | ||
237 | free(s->Protocol.Data.MBUS2.Msg.Buffer); | ||
238 | return ERR_NONE; | ||
239 | } | ||
240 | |||
241 | GSM_Protocol_Functions MBUS2Protocol = { | ||
242 | MBUS2_WriteMessage, | ||
243 | MBUS2_StateMachine, | ||
244 | MBUS2_Initialise, | ||
245 | MBUS2_Terminate | ||
246 | }; | ||
247 | |||
248 | #endif | ||
249 | |||
250 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
251 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
252 | */ | ||
diff --git a/gammu/emb/common/protocol/nokia/mbus2.h b/gammu/emb/common/protocol/nokia/mbus2.h new file mode 100644 index 0000000..86fcab6 --- a/dev/null +++ b/gammu/emb/common/protocol/nokia/mbus2.h | |||
@@ -0,0 +1,28 @@ | |||
1 | /* (c) 2001-2003 by Marcin Wiacek */ | ||
2 | /* based on some work from MyGnokii */ | ||
3 | |||
4 | #ifndef mbus2_h | ||
5 | #define mbus2_h | ||
6 | |||
7 | #include "../protocol.h" | ||
8 | |||
9 | #define MBUS2_FRAME_ID 0x1f | ||
10 | #define MBUS2_DEVICE_PHONE 0x00 /* Nokia mobile phone */ | ||
11 | #define MBUS2_DEVICE_PC 0x10 /* Our PC (MBUS) */ | ||
12 | #define MBUS2_ACK_BYTE 0x7f /* Acknowledge of the received frame */ | ||
13 | |||
14 | typedef struct { | ||
15 | int MsgSequenceNumber; | ||
16 | int MsgRXState; | ||
17 | GSM_Protocol_MessageMsg; | ||
18 | } GSM_Protocol_MBUS2Data; | ||
19 | |||
20 | #ifndef GSM_USED_SERIALDEVICE | ||
21 | # define GSM_USED_SERIALDEVICE | ||
22 | #endif | ||
23 | |||
24 | #endif | ||
25 | |||
26 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
27 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
28 | */ | ||
diff --git a/gammu/emb/common/protocol/nokia/phonet.c b/gammu/emb/common/protocol/nokia/phonet.c new file mode 100644 index 0000000..bc5717d --- a/dev/null +++ b/gammu/emb/common/protocol/nokia/phonet.c | |||
@@ -0,0 +1,217 @@ | |||
1 | /* (c) 2002-2003 by Marcin Wiacek */ | ||
2 | /* based on some work from Gnokii */ | ||
3 | |||
4 | #include "../../gsmstate.h" | ||
5 | |||
6 | #if defined(GSM_ENABLE_IRDA) || defined(GSM_ENABLE_PHONETBLUE) || defined(GSM_ENABLE_BLUEPHONET) | ||
7 | |||
8 | #include <stdio.h> | ||
9 | #include <string.h> | ||
10 | |||
11 | #include "../../gsmcomon.h" | ||
12 | #include "phonet.h" | ||
13 | |||
14 | static GSM_Error PHONET_WriteMessage (GSM_StateMachine *s, | ||
15 | unsigned char *MsgBuffer, | ||
16 | int MsgLength, | ||
17 | unsigned char MsgType) | ||
18 | { | ||
19 | unsigned char *buffer2; | ||
20 | int sent; | ||
21 | |||
22 | GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType); | ||
23 | |||
24 | buffer2 = (unsigned char *)malloc(MsgLength + 6); | ||
25 | |||
26 | buffer2[0] = PHONET_FRAME_ID, | ||
27 | buffer2[1] = PHONET_DEVICE_PHONE; //destination | ||
28 | buffer2[2] = PHONET_DEVICE_PC; //source | ||
29 | |||
30 | if (s->ConnectionType==GCT_PHONETBLUE || s->ConnectionType==GCT_BLUEPHONET) { | ||
31 | buffer2[0] = PHONET_BLUE_FRAME_ID; | ||
32 | buffer2[1] = PHONET_DEVICE_PHONE;//destination | ||
33 | buffer2[2] = PHONET_BLUE_DEVICE_PC;//source | ||
34 | } | ||
35 | |||
36 | buffer2[3] = MsgType; | ||
37 | buffer2[4] = MsgLength / 256; | ||
38 | buffer2[5] = MsgLength % 256; | ||
39 | |||
40 | memcpy(buffer2 + 6, MsgBuffer, MsgLength); | ||
41 | |||
42 | GSM_DumpMessageLevel2(s, buffer2+6, MsgLength, MsgType); | ||
43 | |||
44 | /* Sending to phone */ | ||
45 | sent = s->Device.Functions->WriteDevice(s,buffer2,MsgLength+6); | ||
46 | |||
47 | free(buffer2); | ||
48 | |||
49 | if (sent!=MsgLength+6) return ERR_DEVICEWRITEERROR; | ||
50 | return ERR_NONE; | ||
51 | } | ||
52 | |||
53 | static GSM_Error PHONET_StateMachine(GSM_StateMachine *s, unsigned char rx_char) | ||
54 | { | ||
55 | GSM_Protocol_PHONETData *d = &s->Protocol.Data.PHONET; | ||
56 | bool correct = false; | ||
57 | |||
58 | if (d->MsgRXState==RX_GetMessage) { | ||
59 | d->Msg.Buffer[d->Msg.Count] = rx_char; | ||
60 | d->Msg.Count++; | ||
61 | |||
62 | /* This is not last byte in frame */ | ||
63 | if (d->Msg.Count != d->Msg.Length) return ERR_NONE; | ||
64 | |||
65 | s->Phone.Data.RequestMsg= &d->Msg; | ||
66 | s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); | ||
67 | |||
68 | free(d->Msg.Buffer); | ||
69 | d->Msg.Length = 0; | ||
70 | d->Msg.Buffer = NULL; | ||
71 | |||
72 | d->MsgRXState = RX_Sync; | ||
73 | return ERR_NONE; | ||
74 | } | ||
75 | if (d->MsgRXState==RX_GetLength2) { | ||
76 | d->Msg.Length = d->Msg.Length + rx_char; | ||
77 | d->Msg.Buffer = (unsigned char *)malloc(d->Msg.Length); | ||
78 | |||
79 | d->MsgRXState = RX_GetMessage; | ||
80 | return ERR_NONE; | ||
81 | } | ||
82 | if (d->MsgRXState==RX_GetLength1) { | ||
83 | d->Msg.Length = rx_char * 256; | ||
84 | |||
85 | d->MsgRXState = RX_GetLength2; | ||
86 | return ERR_NONE; | ||
87 | } | ||
88 | if (d->MsgRXState==RX_GetType) { | ||
89 | d->Msg.Type = rx_char; | ||
90 | |||
91 | d->MsgRXState = RX_GetLength1; | ||
92 | return ERR_NONE; | ||
93 | } | ||
94 | if (d->MsgRXState==RX_GetSource) { | ||
95 | if (rx_char != PHONET_DEVICE_PHONE) { | ||
96 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | ||
97 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | ||
98 | smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, PHONET_DEVICE_PHONE); | ||
99 | } | ||
100 | d->MsgRXState = RX_Sync; | ||
101 | return ERR_NONE; | ||
102 | } | ||
103 | d->Msg.Source = rx_char; | ||
104 | |||
105 | d->MsgRXState = RX_GetType; | ||
106 | return ERR_NONE; | ||
107 | } | ||
108 | if (d->MsgRXState==RX_GetDestination) { | ||
109 | switch (s->ConnectionType) { | ||
110 | case GCT_IRDAPHONET: | ||
111 | if (rx_char == PHONET_DEVICE_PC) correct = true; | ||
112 | break; | ||
113 | case GCT_PHONETBLUE: | ||
114 | case GCT_BLUEPHONET: | ||
115 | if (rx_char == PHONET_BLUE_DEVICE_PC) correct = true; | ||
116 | break; | ||
117 | default: | ||
118 | break; | ||
119 | } | ||
120 | if (!correct) { | ||
121 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | ||
122 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | ||
123 | smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, PHONET_DEVICE_PC); | ||
124 | } | ||
125 | d->MsgRXState = RX_Sync; | ||
126 | return ERR_NONE; | ||
127 | } | ||
128 | d->Msg.Destination = rx_char; | ||
129 | |||
130 | d->MsgRXState = RX_GetSource; | ||
131 | return ERR_NONE; | ||
132 | } | ||
133 | if (d->MsgRXState==RX_Sync) { | ||
134 | switch (s->ConnectionType) { | ||
135 | case GCT_IRDAPHONET: | ||
136 | if (rx_char == PHONET_FRAME_ID) correct = true; | ||
137 | break; | ||
138 | case GCT_PHONETBLUE: | ||
139 | case GCT_BLUEPHONET: | ||
140 | if (rx_char == PHONET_BLUE_FRAME_ID) correct = true; | ||
141 | break; | ||
142 | default: | ||
143 | break; | ||
144 | } | ||
145 | if (!correct) { | ||
146 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | ||
147 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | ||
148 | smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, PHONET_FRAME_ID); | ||
149 | } | ||
150 | return ERR_NONE; | ||
151 | } | ||
152 | d->Msg.Count = 0; | ||
153 | |||
154 | d->MsgRXState = RX_GetDestination; | ||
155 | return ERR_NONE; | ||
156 | } | ||
157 | return ERR_NONE; | ||
158 | } | ||
159 | |||
160 | static GSM_Error PHONET_Initialise(GSM_StateMachine *s) | ||
161 | { | ||
162 | int total = 0, i, n; | ||
163 | GSM_Protocol_PHONETData *d = &s->Protocol.Data.PHONET; | ||
164 | unsigned char req[50]; | ||
165 | |||
166 | d->Msg.Length= 0; | ||
167 | d->Msg.Buffer= NULL; | ||
168 | d->MsgRXState= RX_Sync; | ||
169 | |||
170 | if (s->ConnectionType == GCT_PHONETBLUE || s->ConnectionType == GCT_BLUEPHONET) { | ||
171 | /* Send frame in PHONET style */ | ||
172 | req[0] = PHONET_BLUE_FRAME_ID; req[1] = PHONET_DEVICE_PHONE; | ||
173 | req[2] = PHONET_BLUE_DEVICE_PC; req[3] = 0xD0; | ||
174 | req[4] = 0x00; req[5] = 0x01; | ||
175 | req[6] = 0x04; | ||
176 | if (s->Device.Functions->WriteDevice(s,req,7) != 7) return ERR_DEVICEWRITEERROR; | ||
177 | |||
178 | while (total < 7) { | ||
179 | n = s->Device.Functions->ReadDevice(s, req + total, 50 - total); | ||
180 | total += n; | ||
181 | } | ||
182 | |||
183 | /* Answer frame in PHONET style */ | ||
184 | req[10] = PHONET_BLUE_FRAME_ID; req[11] = PHONET_BLUE_DEVICE_PC; | ||
185 | req[12] = PHONET_DEVICE_PHONE;req[13] = 0xD0; | ||
186 | req[14] = 0x00; req[15] = 0x01; | ||
187 | req[16] = 0x05; | ||
188 | |||
189 | for (i = 0; i < 7; i++) { | ||
190 | if (req[i] != req[10+i]) { | ||
191 | smprintf(s,"Incorrect byte in the answer\n"); | ||
192 | return ERR_UNKNOWN; | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | |||
197 | return ERR_NONE; | ||
198 | } | ||
199 | |||
200 | static GSM_Error PHONET_Terminate(GSM_StateMachine *s) | ||
201 | { | ||
202 | free(s->Protocol.Data.PHONET.Msg.Buffer); | ||
203 | return ERR_NONE; | ||
204 | } | ||
205 | |||
206 | GSM_Protocol_Functions PHONETProtocol = { | ||
207 | PHONET_WriteMessage, | ||
208 | PHONET_StateMachine, | ||
209 | PHONET_Initialise, | ||
210 | PHONET_Terminate | ||
211 | }; | ||
212 | |||
213 | #endif | ||
214 | |||
215 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
216 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
217 | */ | ||
diff --git a/gammu/emb/common/protocol/nokia/phonet.h b/gammu/emb/common/protocol/nokia/phonet.h new file mode 100644 index 0000000..2f6e836 --- a/dev/null +++ b/gammu/emb/common/protocol/nokia/phonet.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /* (c) 2002-2003 by Marcin Wiacek */ | ||
2 | /* based on some work from Gnokii */ | ||
3 | |||
4 | #ifndef PHONET_h | ||
5 | #define PHONET_h | ||
6 | |||
7 | #include "../protocol.h" | ||
8 | |||
9 | #define PHONET_FRAME_ID 0x14 | ||
10 | #define PHONET_BLUE_FRAME_ID0x19 | ||
11 | #define PHONET_DEVICE_PHONE 0x00 /* Nokia mobile phone */ | ||
12 | #define PHONET_DEVICE_PC 0x0c /* Our PC */ | ||
13 | #define PHONET_BLUE_DEVICE_PC 0x10 /* Our PC */ | ||
14 | |||
15 | typedef struct { | ||
16 | int MsgRXState; | ||
17 | GSM_Protocol_MessageMsg; | ||
18 | } GSM_Protocol_PHONETData; | ||
19 | |||
20 | #if defined(GSM_ENABLE_IRDAPHONET) | ||
21 | # ifndef GSM_USED_IRDADEVICE | ||
22 | # define GSM_USED_IRDADEVICE | ||
23 | # endif | ||
24 | #endif | ||
25 | #if defined(GSM_ENABLE_BLUEPHONET) | ||
26 | # ifndef GSM_USED_BLUETOOTHDEVICE | ||
27 | # define GSM_USED_BLUETOOTHDEVICE | ||
28 | # endif | ||
29 | #endif | ||
30 | |||
31 | #endif | ||
32 | |||
33 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
34 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
35 | */ | ||