summaryrefslogtreecommitdiffabout
path: root/gammu/emb/common/protocol
Unidiff
Diffstat (limited to 'gammu/emb/common/protocol') (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/common/protocol/nokia/fbus2.c10
-rw-r--r--gammu/emb/common/protocol/nokia/fbus2.h9
-rw-r--r--gammu/emb/common/protocol/nokia/phonet.c9
-rw-r--r--gammu/emb/common/protocol/nokia/phonet.h9
4 files changed, 37 insertions, 0 deletions
diff --git a/gammu/emb/common/protocol/nokia/fbus2.c b/gammu/emb/common/protocol/nokia/fbus2.c
index 2b41f8b..967eaa4 100644
--- a/gammu/emb/common/protocol/nokia/fbus2.c
+++ b/gammu/emb/common/protocol/nokia/fbus2.c
@@ -1,243 +1,253 @@
1/* (c) 2002-2003 by Marcin Wiacek */ 1/* (c) 2002-2003 by Marcin Wiacek */
2/* based on some work from MyGnokii (www.mwiacek.com) */ 2/* based on some work from MyGnokii (www.mwiacek.com) */
3/* Based on some work from Gnokii (www.gnokii.org) 3/* Based on some work from Gnokii (www.gnokii.org)
4 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot 4 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
5 * GNU GPL version 2 or later 5 * GNU GPL version 2 or later
6 */ 6 */
7/* Due to a problem in the source code management, the names of some of
8 * the authors have unfortunately been lost. We do not mean to belittle
9 * their efforts and hope they will contact us to see their names
10 * properly added to the Copyright notice above.
11 * Having published their contributions under the terms of the GNU
12 * General Public License (GPL) [version 2], the Copyright of these
13 * authors will remain respected by adhering to the license they chose
14 * to publish their code under.
15 */
7 16
8#include "../../gsmstate.h" 17#include "../../gsmstate.h"
9 18
10#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) 19#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)
11 20
12#include <stdio.h> 21#include <stdio.h>
13#include <string.h> 22#include <string.h>
14 23
15#include "../../gsmcomon.h" 24#include "../../gsmcomon.h"
16#include "fbus2.h" 25#include "fbus2.h"
17 26
18 static GSM_Error FBUS2_WriteFrame(GSM_StateMachine *s, 27 static GSM_Error FBUS2_WriteFrame(GSM_StateMachine *s,
19 unsigned char *MsgBuffer, 28 unsigned char *MsgBuffer,
20 int MsgLength, 29 int MsgLength,
21 unsigned char MsgType) 30 unsigned char MsgType)
22{ 31{
23 unsigned char buffer2[FBUS2_MAX_TRANSMIT_LENGTH + 10]; 32 unsigned char buffer2[FBUS2_MAX_TRANSMIT_LENGTH + 10];
24 unsigned char checksum=0; 33 unsigned char checksum=0;
25 int i, len, sent; 34 int i, len, sent;
26 35
27 buffer2[0] = FBUS2_FRAME_ID; 36 buffer2[0] = FBUS2_FRAME_ID;
28 if (s->ConnectionType==GCT_FBUS2IRDA) buffer2[0] = FBUS2_IRDA_FRAME_ID; 37 if (s->ConnectionType==GCT_FBUS2IRDA) buffer2[0] = FBUS2_IRDA_FRAME_ID;
29 38
30 buffer2[1] = FBUS2_DEVICE_PHONE; //destination 39 buffer2[1] = FBUS2_DEVICE_PHONE; //destination
31 buffer2[2] = FBUS2_DEVICE_PC; //source 40 buffer2[2] = FBUS2_DEVICE_PC; //source
32 buffer2[3]= MsgType; 41 buffer2[3]= MsgType;
33 buffer2[4]= MsgLength / 256; 42 buffer2[4]= MsgLength / 256;
34 buffer2[5]= MsgLength % 256; 43 buffer2[5]= MsgLength % 256;
35 44
36 memcpy(buffer2 + 6, MsgBuffer, MsgLength); 45 memcpy(buffer2 + 6, MsgBuffer, MsgLength);
37 len = MsgLength + 6; 46 len = MsgLength + 6;
38 47
39 /* Odd messages require additional 0x00 byte */ 48 /* Odd messages require additional 0x00 byte */
40 if (MsgLength % 2) buffer2[len++] = 0x00; 49 if (MsgLength % 2) buffer2[len++] = 0x00;
41 50
42 checksum = 0; 51 checksum = 0;
43 for (i = 0; i < len; i+=2) checksum ^= buffer2[i]; 52 for (i = 0; i < len; i+=2) checksum ^= buffer2[i];
44 buffer2[len++] = checksum; 53 buffer2[len++] = checksum;
45 54
46 checksum = 0; 55 checksum = 0;
47 for (i = 1; i < len; i+=2) checksum ^= buffer2[i]; 56 for (i = 1; i < len; i+=2) checksum ^= buffer2[i];
48 buffer2[len++] = checksum; 57 buffer2[len++] = checksum;
49 58
50 /* Sending to phone */ 59 /* Sending to phone */
51 sent=s->Device.Functions->WriteDevice(s,buffer2,len); 60 sent=s->Device.Functions->WriteDevice(s,buffer2,len);
52 if (sent!=len) return ERR_DEVICEWRITEERROR; 61 if (sent!=len) return ERR_DEVICEWRITEERROR;
53 62
54 return ERR_NONE; 63 return ERR_NONE;
55} 64}
56 65
57 static GSM_Error FBUS2_WriteMessage (GSM_StateMachine *s, 66 static GSM_Error FBUS2_WriteMessage (GSM_StateMachine *s,
58 unsigned char *MsgBuffer, 67 unsigned char *MsgBuffer,
59 int MsgLength, 68 int MsgLength,
60 unsigned char MsgType) 69 unsigned char MsgType)
61{ 70{
62 int i, nom, togo, thislength; /* number of messages, ... */ 71 int i, nom, togo, thislength; /* number of messages, ... */
63 unsigned char buffer2[FBUS2_MAX_TRANSMIT_LENGTH + 2], seqnum; 72 unsigned char buffer2[FBUS2_MAX_TRANSMIT_LENGTH + 2], seqnum;
64 GSM_Protocol_FBUS2Data*d = &s->Protocol.Data.FBUS2; 73 GSM_Protocol_FBUS2Data*d = &s->Protocol.Data.FBUS2;
65 GSM_Error error; 74 GSM_Error error;
66 75
67 GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType); 76 GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType);
68 77
69 nom = (MsgLength + FBUS2_MAX_TRANSMIT_LENGTH - 1) / FBUS2_MAX_TRANSMIT_LENGTH; 78 nom = (MsgLength + FBUS2_MAX_TRANSMIT_LENGTH - 1) / FBUS2_MAX_TRANSMIT_LENGTH;
70 togo = MsgLength; 79 togo = MsgLength;
71 80
72 for (i = 0; i < nom; i++) { 81 for (i = 0; i < nom; i++) {
73 seqnum = d->MsgSequenceNumber; 82 seqnum = d->MsgSequenceNumber;
74 if (i==0) seqnum = seqnum + 0x40; 83 if (i==0) seqnum = seqnum + 0x40;
75 d->MsgSequenceNumber = (d->MsgSequenceNumber + 1) & 0x07; 84 d->MsgSequenceNumber = (d->MsgSequenceNumber + 1) & 0x07;
76 85
77 thislength = togo; 86 thislength = togo;
78 if (togo > FBUS2_MAX_TRANSMIT_LENGTH) thislength = FBUS2_MAX_TRANSMIT_LENGTH; 87 if (togo > FBUS2_MAX_TRANSMIT_LENGTH) thislength = FBUS2_MAX_TRANSMIT_LENGTH;
79 memcpy(buffer2, MsgBuffer + (MsgLength - togo), thislength); 88 memcpy(buffer2, MsgBuffer + (MsgLength - togo), thislength);
80 buffer2[thislength]= nom - i; 89 buffer2[thislength]= nom - i;
81 buffer2[thislength + 1]= seqnum; 90 buffer2[thislength + 1]= seqnum;
82 togo = togo - thislength; 91 togo = togo - thislength;
83 92
84 GSM_DumpMessageLevel2(s, buffer2, thislength, MsgType); 93 GSM_DumpMessageLevel2(s, buffer2, thislength, MsgType);
85 94
86 error=FBUS2_WriteFrame(s, buffer2, thislength + 2, MsgType); 95 error=FBUS2_WriteFrame(s, buffer2, thislength + 2, MsgType);
87 if (error!=ERR_NONE) return error; 96 if (error!=ERR_NONE) return error;
88 } 97 }
89 98
90 return ERR_NONE; 99 return ERR_NONE;
91} 100}
92 101
93 static GSM_Error FBUS2_SendAck(GSM_StateMachine *s, 102 static GSM_Error FBUS2_SendAck(GSM_StateMachine *s,
94 unsigned char MsgType, 103 unsigned char MsgType,
95 unsigned char MsgSequence) 104 unsigned char MsgSequence)
96{ 105{
97 unsigned char buffer2[2]; 106 unsigned char buffer2[2];
98 107
99 buffer2[0] = MsgType; 108 buffer2[0] = MsgType;
100 buffer2[1] = MsgSequence; 109 buffer2[1] = MsgSequence;
101 110
102 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || 111 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
103 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { 112 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
104 smprintf(s,"[Sending Ack of type %02x, seq %x]\n",buffer2[0],buffer2[1]); 113 smprintf(s,"[Sending Ack of type %02x, seq %x]\n",buffer2[0],buffer2[1]);
105 } 114 }
106 115
107 /* Sending to phone */ 116 /* Sending to phone */
108 return FBUS2_WriteFrame(s, buffer2, 2, FBUS2_ACK_BYTE); 117 return FBUS2_WriteFrame(s, buffer2, 2, FBUS2_ACK_BYTE);
109} 118}
110 119
111static GSM_Error FBUS2_StateMachine(GSM_StateMachine *s, unsigned char rx_char) 120static GSM_Error FBUS2_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
112{ 121{
113 GSM_Protocol_FBUS2Data *d = &s->Protocol.Data.FBUS2; 122 GSM_Protocol_FBUS2Data *d = &s->Protocol.Data.FBUS2;
114 unsigned char frm_num, seq_num; 123 unsigned char frm_num, seq_num;
115 bool correct = false; 124 bool correct = false;
116 125
117 /* XOR the byte with the earlier checksum */ 126 /* XOR the byte with the earlier checksum */
118 d->Msg.CheckSum[d->Msg.Count & 1] ^= rx_char; 127 d->Msg.CheckSum[d->Msg.Count & 1] ^= rx_char;
119 128
120 if (d->MsgRXState == RX_GetMessage) { 129 if (d->MsgRXState == RX_GetMessage) {
121 d->Msg.Buffer[d->Msg.Count] = rx_char; 130 d->Msg.Buffer[d->Msg.Count] = rx_char;
122 d->Msg.Count++; 131 d->Msg.Count++;
123 132
124 /* This is not last byte in frame */ 133 /* This is not last byte in frame */
125 if (d->Msg.Count != d->Msg.Length+(d->Msg.Length%2)+2) return ERR_NONE; 134 if (d->Msg.Count != d->Msg.Length+(d->Msg.Length%2)+2) return ERR_NONE;
126 135
127 /* Checksum is incorrect */ 136 /* Checksum is incorrect */
128 if (d->Msg.CheckSum[0] != d->Msg.CheckSum[1]) { 137 if (d->Msg.CheckSum[0] != d->Msg.CheckSum[1]) {
129 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 138 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
130 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 139 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
131 smprintf(s,"[ERROR: checksum]\n"); 140 smprintf(s,"[ERROR: checksum]\n");
132 } 141 }
133 free(d->Msg.Buffer); 142 free(d->Msg.Buffer);
134 d->Msg.Length = 0; 143 d->Msg.Length = 0;
135 d->Msg.Buffer = NULL; 144 d->Msg.Buffer = NULL;
136 145
137 d->MsgRXState = RX_Sync; 146 d->MsgRXState = RX_Sync;
138 return ERR_NONE; 147 return ERR_NONE;
139 } 148 }
140 149
141 seq_num = d->Msg.Buffer[d->Msg.Length-1]; 150 seq_num = d->Msg.Buffer[d->Msg.Length-1];
142 151
143 if (d->Msg.Type == FBUS2_ACK_BYTE) { 152 if (d->Msg.Type == FBUS2_ACK_BYTE) {
144 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || 153 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
145 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { 154 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
146 smprintf(s, "[Received Ack of type %02x, seq %02x]\n",d->Msg.Buffer[0],seq_num); 155 smprintf(s, "[Received Ack of type %02x, seq %02x]\n",d->Msg.Buffer[0],seq_num);
147 } 156 }
157 free(d->Msg.Buffer);
148 158
149 d->MsgRXState = RX_Sync; 159 d->MsgRXState = RX_Sync;
150 return ERR_NONE; 160 return ERR_NONE;
151 } 161 }
152 162
153 frm_num = d->Msg.Buffer[d->Msg.Length-2]; 163 frm_num = d->Msg.Buffer[d->Msg.Length-2];
154 164
155 if ((seq_num & 0x40) == 0x40) { 165 if ((seq_num & 0x40) == 0x40) {
156 d->FramesToGo = frm_num; 166 d->FramesToGo = frm_num;
157 d->MultiMsg.Length= 0; 167 d->MultiMsg.Length= 0;
158 d->MultiMsg.Type= d->Msg.Type; 168 d->MultiMsg.Type= d->Msg.Type;
159 d->MultiMsg.Destination= d->Msg.Destination; 169 d->MultiMsg.Destination= d->Msg.Destination;
160 d->MultiMsg.Source= d->Msg.Source; 170 d->MultiMsg.Source= d->Msg.Source;
161 } 171 }
162 172
163 if ((seq_num & 0x40) != 0x40 && d->FramesToGo != frm_num) { 173 if ((seq_num & 0x40) != 0x40 && d->FramesToGo != frm_num) {
164 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 174 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
165 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 175 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
166 smprintf(s, "[ERROR: Missed part of multiframe msg]\n"); 176 smprintf(s, "[ERROR: Missed part of multiframe msg]\n");
167 } 177 }
168 178
169 free(d->Msg.Buffer); 179 free(d->Msg.Buffer);
170 d->Msg.Length = 0; 180 d->Msg.Length = 0;
171 d->Msg.Buffer = NULL; 181 d->Msg.Buffer = NULL;
172 182
173 d->MsgRXState = RX_Sync; 183 d->MsgRXState = RX_Sync;
174 return ERR_NONE; 184 return ERR_NONE;
175 } 185 }
176 186
177 if ((seq_num & 0x40) != 0x40 && d->Msg.Type != d->MultiMsg.Type) { 187 if ((seq_num & 0x40) != 0x40 && d->Msg.Type != d->MultiMsg.Type) {
178 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 188 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
179 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 189 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
180 smprintf(s, "[ERROR: Multiframe msg in multiframe msg]\n"); 190 smprintf(s, "[ERROR: Multiframe msg in multiframe msg]\n");
181 } 191 }
182 192
183 free(d->Msg.Buffer); 193 free(d->Msg.Buffer);
184 d->Msg.Length = 0; 194 d->Msg.Length = 0;
185 d->Msg.Buffer = NULL; 195 d->Msg.Buffer = NULL;
186 196
187 d->MsgRXState = RX_Sync; 197 d->MsgRXState = RX_Sync;
188 return ERR_NONE; 198 return ERR_NONE;
189 } 199 }
190 200
191 if (d->MultiMsg.BufferUsed < d->MultiMsg.Length+d->Msg.Length-2) { 201 if (d->MultiMsg.BufferUsed < d->MultiMsg.Length+d->Msg.Length-2) {
192 d->MultiMsg.BufferUsed = d->MultiMsg.Length+d->Msg.Length-2; 202 d->MultiMsg.BufferUsed = d->MultiMsg.Length+d->Msg.Length-2;
193 d->MultiMsg.Buffer = (unsigned char *)realloc(d->MultiMsg.Buffer,d->MultiMsg.BufferUsed); 203 d->MultiMsg.Buffer = (unsigned char *)realloc(d->MultiMsg.Buffer,d->MultiMsg.BufferUsed);
194 } 204 }
195 memcpy(d->MultiMsg.Buffer+d->MultiMsg.Length,d->Msg.Buffer,d->Msg.Length-2); 205 memcpy(d->MultiMsg.Buffer+d->MultiMsg.Length,d->Msg.Buffer,d->Msg.Length-2);
196 d->MultiMsg.Length = d->MultiMsg.Length+d->Msg.Length-2; 206 d->MultiMsg.Length = d->MultiMsg.Length+d->Msg.Length-2;
197 207
198 free(d->Msg.Buffer); 208 free(d->Msg.Buffer);
199 d->Msg.Length = 0; 209 d->Msg.Length = 0;
200 d->Msg.Buffer = NULL; 210 d->Msg.Buffer = NULL;
201 211
202 d->FramesToGo--; 212 d->FramesToGo--;
203 213
204 /* do not ack debug trace, as this could generate a 214 /* do not ack debug trace, as this could generate a
205 * (feedback loop) flood of which even Noah would be scared. 215 * (feedback loop) flood of which even Noah would be scared.
206 */ 216 */
207 if (d->Msg.Type != 0) { 217 if (d->Msg.Type != 0) {
208 FBUS2_SendAck(s,d->Msg.Type,((unsigned char)(seq_num & 0x0f))); 218 FBUS2_SendAck(s,d->Msg.Type,((unsigned char)(seq_num & 0x0f)));
209 } 219 }
210 220
211 if (d->FramesToGo == 0) { 221 if (d->FramesToGo == 0) {
212 s->Phone.Data.RequestMsg= &d->MultiMsg; 222 s->Phone.Data.RequestMsg= &d->MultiMsg;
213 s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); 223 s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s);
214 } 224 }
215 d->MsgRXState = RX_Sync; 225 d->MsgRXState = RX_Sync;
216 return ERR_NONE; 226 return ERR_NONE;
217 } 227 }
218 if (d->MsgRXState == RX_GetLength2) { 228 if (d->MsgRXState == RX_GetLength2) {
219 d->Msg.Length = d->Msg.Length + rx_char; 229 d->Msg.Length = d->Msg.Length + rx_char;
220 d->Msg.Buffer = (unsigned char *)malloc(d->Msg.Length+3); 230 d->Msg.Buffer = (unsigned char *)malloc(d->Msg.Length+3);
221 d->MsgRXState = RX_GetMessage; 231 d->MsgRXState = RX_GetMessage;
222 return ERR_NONE; 232 return ERR_NONE;
223 } 233 }
224 if (d->MsgRXState == RX_GetLength1) { 234 if (d->MsgRXState == RX_GetLength1) {
225 d->Msg.Length = rx_char * 256; 235 d->Msg.Length = rx_char * 256;
226 d->MsgRXState = RX_GetLength2; 236 d->MsgRXState = RX_GetLength2;
227 return ERR_NONE; 237 return ERR_NONE;
228 } 238 }
229 if (d->MsgRXState == RX_GetType) { 239 if (d->MsgRXState == RX_GetType) {
230 d->Msg.Type = rx_char; 240 d->Msg.Type = rx_char;
231 d->MsgRXState = RX_GetLength1; 241 d->MsgRXState = RX_GetLength1;
232 return ERR_NONE; 242 return ERR_NONE;
233 } 243 }
234 if (d->MsgRXState == RX_GetSource) { 244 if (d->MsgRXState == RX_GetSource) {
235 if (rx_char != FBUS2_DEVICE_PHONE) { 245 if (rx_char != FBUS2_DEVICE_PHONE) {
236 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 246 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
237 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 247 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
238 smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, FBUS2_DEVICE_PHONE); 248 smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, FBUS2_DEVICE_PHONE);
239 } 249 }
240 250
241 d->MsgRXState = RX_Sync; 251 d->MsgRXState = RX_Sync;
242 return ERR_NONE; 252 return ERR_NONE;
243 } 253 }
diff --git a/gammu/emb/common/protocol/nokia/fbus2.h b/gammu/emb/common/protocol/nokia/fbus2.h
index 8dbcb07..3d31006 100644
--- a/gammu/emb/common/protocol/nokia/fbus2.h
+++ b/gammu/emb/common/protocol/nokia/fbus2.h
@@ -1,42 +1,51 @@
1/* (c) 2002-2003 by Marcin Wiacek */ 1/* (c) 2002-2003 by Marcin Wiacek */
2/* based on some work from MyGnokii (www.mwiacek.com) */ 2/* based on some work from MyGnokii (www.mwiacek.com) */
3/* Based on some work from Gnokii (www.gnokii.org) 3/* Based on some work from Gnokii (www.gnokii.org)
4 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot 4 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
5 * GNU GPL version 2 or later 5 * GNU GPL version 2 or later
6 */ 6 */
7/* Due to a problem in the source code management, the names of some of
8 * the authors have unfortunately been lost. We do not mean to belittle
9 * their efforts and hope they will contact us to see their names
10 * properly added to the Copyright notice above.
11 * Having published their contributions under the terms of the GNU
12 * General Public License (GPL) [version 2], the Copyright of these
13 * authors will remain respected by adhering to the license they chose
14 * to publish their code under.
15 */
7 16
8#ifndef fbus2_h 17#ifndef fbus2_h
9#define fbus2_h 18#define fbus2_h
10 19
11#include "../protocol.h" 20#include "../protocol.h"
12 21
13 #define FBUS2_FRAME_ID 0x1e 22 #define FBUS2_FRAME_ID 0x1e
14 #define FBUS2_IRDA_FRAME_ID 0x1c 23 #define FBUS2_IRDA_FRAME_ID 0x1c
15 #define FBUS2_DEVICE_PHONE 0x00 /* Nokia mobile phone */ 24 #define FBUS2_DEVICE_PHONE 0x00 /* Nokia mobile phone */
16 #define FBUS2_DEVICE_PC 0x0c /* Our PC */ 25 #define FBUS2_DEVICE_PC 0x0c /* Our PC */
17 #define FBUS2_ACK_BYTE 0x7f /* Acknowledge of the received frame */ 26 #define FBUS2_ACK_BYTE 0x7f /* Acknowledge of the received frame */
18 27
19#define FBUS2_MAX_TRANSMIT_LENGTH 120 28#define FBUS2_MAX_TRANSMIT_LENGTH 120
20 29
21typedef struct { 30typedef struct {
22 int MsgSequenceNumber; 31 int MsgSequenceNumber;
23 int MsgRXState; 32 int MsgRXState;
24 int FramesToGo; 33 int FramesToGo;
25 GSM_Protocol_MessageMultiMsg; 34 GSM_Protocol_MessageMultiMsg;
26 GSM_Protocol_MessageMsg; 35 GSM_Protocol_MessageMsg;
27} GSM_Protocol_FBUS2Data; 36} GSM_Protocol_FBUS2Data;
28 37
29#ifndef GSM_USED_SERIALDEVICE 38#ifndef GSM_USED_SERIALDEVICE
30# define GSM_USED_SERIALDEVICE 39# define GSM_USED_SERIALDEVICE
31#endif 40#endif
32#if defined(GSM_ENABLE_BLUEFBUS2) 41#if defined(GSM_ENABLE_BLUEFBUS2)
33# ifndef GSM_USED_BLUETOOTHDEVICE 42# ifndef GSM_USED_BLUETOOTHDEVICE
34# define GSM_USED_BLUETOOTHDEVICE 43# define GSM_USED_BLUETOOTHDEVICE
35# endif 44# endif
36#endif 45#endif
37 46
38#endif 47#endif
39 48
40/* How should editor hadle tabs in this file? Add editor commands here. 49/* How should editor hadle tabs in this file? Add editor commands here.
41 * vim: noexpandtab sw=8 ts=8 sts=8: 50 * vim: noexpandtab sw=8 ts=8 sts=8:
42 */ 51 */
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
56static GSM_Error PHONET_StateMachine(GSM_StateMachine *s, unsigned char rx_char) 65static 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);
diff --git a/gammu/emb/common/protocol/nokia/phonet.h b/gammu/emb/common/protocol/nokia/phonet.h
index e750bbd..7626c23 100644
--- a/gammu/emb/common/protocol/nokia/phonet.h
+++ b/gammu/emb/common/protocol/nokia/phonet.h
@@ -1,38 +1,47 @@
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#ifndef PHONET_h 16#ifndef PHONET_h
8#define PHONET_h 17#define PHONET_h
9 18
10#include "../protocol.h" 19#include "../protocol.h"
11 20
12 #define PHONET_FRAME_ID 0x14 21 #define PHONET_FRAME_ID 0x14
13 #define PHONET_BLUE_FRAME_ID0x19 22 #define PHONET_BLUE_FRAME_ID0x19
14 #define PHONET_DEVICE_PHONE 0x00 /* Nokia mobile phone */ 23 #define PHONET_DEVICE_PHONE 0x00 /* Nokia mobile phone */
15 #define PHONET_DEVICE_PC 0x0c /* Our PC */ 24 #define PHONET_DEVICE_PC 0x0c /* Our PC */
16#define PHONET_BLUE_DEVICE_PC 0x10 /* Our PC */ 25#define PHONET_BLUE_DEVICE_PC 0x10 /* Our PC */
17 26
18typedef struct { 27typedef struct {
19 int MsgRXState; 28 int MsgRXState;
20 GSM_Protocol_MessageMsg; 29 GSM_Protocol_MessageMsg;
21} GSM_Protocol_PHONETData; 30} GSM_Protocol_PHONETData;
22 31
23#if defined(GSM_ENABLE_IRDAPHONET) 32#if defined(GSM_ENABLE_IRDAPHONET)
24# ifndef GSM_USED_IRDADEVICE 33# ifndef GSM_USED_IRDADEVICE
25# define GSM_USED_IRDADEVICE 34# define GSM_USED_IRDADEVICE
26# endif 35# endif
27#endif 36#endif
28#if defined(GSM_ENABLE_BLUEPHONET) 37#if defined(GSM_ENABLE_BLUEPHONET)
29# ifndef GSM_USED_BLUETOOTHDEVICE 38# ifndef GSM_USED_BLUETOOTHDEVICE
30# define GSM_USED_BLUETOOTHDEVICE 39# define GSM_USED_BLUETOOTHDEVICE
31# endif 40# endif
32#endif 41#endif
33 42
34#endif 43#endif
35 44
36/* How should editor hadle tabs in this file? Add editor commands here. 45/* How should editor hadle tabs in this file? Add editor commands here.
37 * vim: noexpandtab sw=8 ts=8 sts=8: 46 * vim: noexpandtab sw=8 ts=8 sts=8:
38 */ 47 */