Diffstat (limited to 'gammu/emb/common/protocol/nokia/phonet.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | gammu/emb/common/protocol/nokia/phonet.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/gammu/emb/common/protocol/nokia/phonet.c b/gammu/emb/common/protocol/nokia/phonet.c index db5bd72..495a1bf 100644 --- a/gammu/emb/common/protocol/nokia/phonet.c +++ b/gammu/emb/common/protocol/nokia/phonet.c | |||
@@ -1,101 +1,110 @@ | |||
1 | /* (c) 2002-2003 by Marcin Wiacek */ | 1 | /* (c) 2002-2003 by Marcin Wiacek */ |
2 | /* Based on some work from Gnokii (www.gnokii.org) | 2 | /* Based on some work from Gnokii (www.gnokii.org) |
3 | * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot | 3 | * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot |
4 | * GNU GPL version 2 or later | 4 | * GNU GPL version 2 or later |
5 | */ | 5 | */ |
6 | /* Due to a problem in the source code management, the names of some of | ||
7 | * the authors have unfortunately been lost. We do not mean to belittle | ||
8 | * their efforts and hope they will contact us to see their names | ||
9 | * properly added to the Copyright notice above. | ||
10 | * Having published their contributions under the terms of the GNU | ||
11 | * General Public License (GPL) [version 2], the Copyright of these | ||
12 | * authors will remain respected by adhering to the license they chose | ||
13 | * to publish their code under. | ||
14 | */ | ||
6 | 15 | ||
7 | #include "../../gsmstate.h" | 16 | #include "../../gsmstate.h" |
8 | 17 | ||
9 | #if defined(GSM_ENABLE_IRDA) || defined(GSM_ENABLE_PHONETBLUE) || defined(GSM_ENABLE_BLUEPHONET) | 18 | #if defined(GSM_ENABLE_IRDA) || defined(GSM_ENABLE_PHONETBLUE) || defined(GSM_ENABLE_BLUEPHONET) |
10 | 19 | ||
11 | #include <stdio.h> | 20 | #include <stdio.h> |
12 | #include <string.h> | 21 | #include <string.h> |
13 | 22 | ||
14 | #include "../../gsmcomon.h" | 23 | #include "../../gsmcomon.h" |
15 | #include "phonet.h" | 24 | #include "phonet.h" |
16 | 25 | ||
17 | static GSM_Error PHONET_WriteMessage (GSM_StateMachine *s, | 26 | static GSM_Error PHONET_WriteMessage (GSM_StateMachine *s, |
18 | unsigned char *MsgBuffer, | 27 | unsigned char *MsgBuffer, |
19 | int MsgLength, | 28 | int MsgLength, |
20 | unsigned char MsgType) | 29 | unsigned char MsgType) |
21 | { | 30 | { |
22 | unsigned char *buffer2; | 31 | unsigned char *buffer2; |
23 | int sent; | 32 | int sent; |
24 | 33 | ||
25 | GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType); | 34 | GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType); |
26 | 35 | ||
27 | buffer2 = (unsigned char *)malloc(MsgLength + 6); | 36 | buffer2 = (unsigned char *)malloc(MsgLength + 6); |
28 | 37 | ||
29 | buffer2[0] = PHONET_FRAME_ID, | 38 | buffer2[0] = PHONET_FRAME_ID, |
30 | buffer2[1] = PHONET_DEVICE_PHONE; //destination | 39 | buffer2[1] = PHONET_DEVICE_PHONE; //destination |
31 | buffer2[2] = PHONET_DEVICE_PC; //source | 40 | buffer2[2] = PHONET_DEVICE_PC; //source |
32 | 41 | ||
33 | if (s->ConnectionType==GCT_PHONETBLUE || s->ConnectionType==GCT_BLUEPHONET) { | 42 | if (s->ConnectionType==GCT_PHONETBLUE || s->ConnectionType==GCT_BLUEPHONET) { |
34 | buffer2[0] = PHONET_BLUE_FRAME_ID; | 43 | buffer2[0] = PHONET_BLUE_FRAME_ID; |
35 | buffer2[1] = PHONET_DEVICE_PHONE;//destination | 44 | buffer2[1] = PHONET_DEVICE_PHONE;//destination |
36 | buffer2[2] = PHONET_BLUE_DEVICE_PC;//source | 45 | buffer2[2] = PHONET_BLUE_DEVICE_PC;//source |
37 | } | 46 | } |
38 | 47 | ||
39 | buffer2[3] = MsgType; | 48 | buffer2[3] = MsgType; |
40 | buffer2[4] = MsgLength / 256; | 49 | buffer2[4] = MsgLength / 256; |
41 | buffer2[5] = MsgLength % 256; | 50 | buffer2[5] = MsgLength % 256; |
42 | 51 | ||
43 | memcpy(buffer2 + 6, MsgBuffer, MsgLength); | 52 | memcpy(buffer2 + 6, MsgBuffer, MsgLength); |
44 | 53 | ||
45 | GSM_DumpMessageLevel2(s, buffer2+6, MsgLength, MsgType); | 54 | GSM_DumpMessageLevel2(s, buffer2+6, MsgLength, MsgType); |
46 | 55 | ||
47 | /* Sending to phone */ | 56 | /* Sending to phone */ |
48 | sent = s->Device.Functions->WriteDevice(s,buffer2,MsgLength+6); | 57 | sent = s->Device.Functions->WriteDevice(s,buffer2,MsgLength+6); |
49 | 58 | ||
50 | free(buffer2); | 59 | free(buffer2); |
51 | 60 | ||
52 | if (sent!=MsgLength+6) return ERR_DEVICEWRITEERROR; | 61 | if (sent!=MsgLength+6) return ERR_DEVICEWRITEERROR; |
53 | return ERR_NONE; | 62 | return ERR_NONE; |
54 | } | 63 | } |
55 | 64 | ||
56 | static GSM_Error PHONET_StateMachine(GSM_StateMachine *s, unsigned char rx_char) | 65 | static GSM_Error PHONET_StateMachine(GSM_StateMachine *s, unsigned char rx_char) |
57 | { | 66 | { |
58 | GSM_Protocol_PHONETData *d = &s->Protocol.Data.PHONET; | 67 | GSM_Protocol_PHONETData *d = &s->Protocol.Data.PHONET; |
59 | bool correct = false; | 68 | bool correct = false; |
60 | 69 | ||
61 | if (d->MsgRXState==RX_GetMessage) { | 70 | if (d->MsgRXState==RX_GetMessage) { |
62 | d->Msg.Buffer[d->Msg.Count] = rx_char; | 71 | d->Msg.Buffer[d->Msg.Count] = rx_char; |
63 | d->Msg.Count++; | 72 | d->Msg.Count++; |
64 | 73 | ||
65 | /* This is not last byte in frame */ | 74 | /* This is not last byte in frame */ |
66 | if (d->Msg.Count != d->Msg.Length) return ERR_NONE; | 75 | if (d->Msg.Count != d->Msg.Length) return ERR_NONE; |
67 | 76 | ||
68 | s->Phone.Data.RequestMsg= &d->Msg; | 77 | s->Phone.Data.RequestMsg= &d->Msg; |
69 | s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); | 78 | s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); |
70 | 79 | ||
71 | free(d->Msg.Buffer); | 80 | free(d->Msg.Buffer); |
72 | d->Msg.Length = 0; | 81 | d->Msg.Length = 0; |
73 | d->Msg.Buffer = NULL; | 82 | d->Msg.Buffer = NULL; |
74 | 83 | ||
75 | d->MsgRXState = RX_Sync; | 84 | d->MsgRXState = RX_Sync; |
76 | return ERR_NONE; | 85 | return ERR_NONE; |
77 | } | 86 | } |
78 | if (d->MsgRXState==RX_GetLength2) { | 87 | if (d->MsgRXState==RX_GetLength2) { |
79 | d->Msg.Length = d->Msg.Length + rx_char; | 88 | d->Msg.Length = d->Msg.Length + rx_char; |
80 | d->Msg.Buffer = (unsigned char *)malloc(d->Msg.Length); | 89 | d->Msg.Buffer = (unsigned char *)malloc(d->Msg.Length); |
81 | 90 | ||
82 | d->MsgRXState = RX_GetMessage; | 91 | d->MsgRXState = RX_GetMessage; |
83 | return ERR_NONE; | 92 | return ERR_NONE; |
84 | } | 93 | } |
85 | if (d->MsgRXState==RX_GetLength1) { | 94 | if (d->MsgRXState==RX_GetLength1) { |
86 | d->Msg.Length = rx_char * 256; | 95 | d->Msg.Length = rx_char * 256; |
87 | 96 | ||
88 | d->MsgRXState = RX_GetLength2; | 97 | d->MsgRXState = RX_GetLength2; |
89 | return ERR_NONE; | 98 | return ERR_NONE; |
90 | } | 99 | } |
91 | if (d->MsgRXState==RX_GetType) { | 100 | if (d->MsgRXState==RX_GetType) { |
92 | d->Msg.Type = rx_char; | 101 | d->Msg.Type = rx_char; |
93 | 102 | ||
94 | d->MsgRXState = RX_GetLength1; | 103 | d->MsgRXState = RX_GetLength1; |
95 | return ERR_NONE; | 104 | return ERR_NONE; |
96 | } | 105 | } |
97 | if (d->MsgRXState==RX_GetSource) { | 106 | if (d->MsgRXState==RX_GetSource) { |
98 | if (rx_char != PHONET_DEVICE_PHONE) { | 107 | if (rx_char != PHONET_DEVICE_PHONE) { |
99 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || | 108 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || |
100 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { | 109 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { |
101 | smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, PHONET_DEVICE_PHONE); | 110 | smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, PHONET_DEVICE_PHONE); |