-rw-r--r-- | gammu/emb/common/protocol/alcatel/alcabus.c | 255 | ||||
-rw-r--r-- | gammu/emb/common/protocol/alcatel/alcabus.h | 61 | ||||
-rw-r--r-- | gammu/emb/common/protocol/at/at.c | 229 | ||||
-rw-r--r-- | gammu/emb/common/protocol/at/at.h | 36 | ||||
-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 | ||||
-rw-r--r-- | gammu/emb/common/protocol/obex/obex.c | 120 | ||||
-rw-r--r-- | gammu/emb/common/protocol/obex/obex.h | 33 | ||||
-rw-r--r-- | gammu/emb/common/protocol/protocol.h | 31 | ||||
-rw-r--r-- | gammu/emb/common/protocol/symbian/mrouter.c | 110 | ||||
-rw-r--r-- | gammu/emb/common/protocol/symbian/mrouter.h | 31 |
15 files changed, 1920 insertions, 0 deletions
diff --git a/gammu/emb/common/protocol/alcatel/alcabus.c b/gammu/emb/common/protocol/alcatel/alcabus.c new file mode 100644 index 0000000..b5b5a30 --- a/dev/null +++ b/gammu/emb/common/protocol/alcatel/alcabus.c | |||
@@ -0,0 +1,255 @@ | |||
1 | /* (c) 2002-2003 by Michal Cihar | ||
2 | * | ||
3 | * Low level functions for communication with Alcatel One Touch phones. | ||
4 | * | ||
5 | * This code implements the protocol used for synchronisation with PC. | ||
6 | */ | ||
7 | #include "../../gsmstate.h" | ||
8 | |||
9 | #if defined(GSM_ENABLE_ALCABUS) | ||
10 | |||
11 | #include <stdio.h> | ||
12 | #include <string.h> | ||
13 | |||
14 | #include "../../gsmcomon.h" | ||
15 | #include "alcabus.h" | ||
16 | |||
17 | static GSM_Error ALCABUS_WriteMessage (GSM_StateMachine *s, unsigned char *data, int len, unsigned char type) | ||
18 | { | ||
19 | GSM_Protocol_ALCABUSData *d = &s->Protocol.Data.ALCABUS; | ||
20 | unsigned char buffer[1024]; | ||
21 | int size = 0; | ||
22 | int sent = 0; | ||
23 | int i = 0, checksum = 0; | ||
24 | |||
25 | if ((type == 0) && (len == 0)) return ERR_NONE; | ||
26 | |||
27 | buffer[0] = ALCATEL_HEADER; | ||
28 | buffer[1] = type; | ||
29 | switch (type) { | ||
30 | case ALCATEL_CONNECT: | ||
31 | buffer[2] = 0x0A; | ||
32 | buffer[3] = 0x04; | ||
33 | buffer[4] = 0x00; | ||
34 | size = 5; | ||
35 | d->next_frame = ALCATEL_CONNECT_ACK; | ||
36 | d->busy = true; | ||
37 | break; | ||
38 | case ALCATEL_DISCONNECT: | ||
39 | size = 2; | ||
40 | d->next_frame = ALCATEL_DISCONNECT_ACK; | ||
41 | d->busy = true; | ||
42 | break; | ||
43 | case ALCATEL_DATA: | ||
44 | buffer[2] = d->out_counter; | ||
45 | |||
46 | /* Increase outgoing packet counter */ | ||
47 | if (d->out_counter == ALCATEL_MAX_COUNTER) d->out_counter = 0; | ||
48 | else d->out_counter++; | ||
49 | |||
50 | buffer[3] = '\0'; | ||
51 | buffer[4] = len; | ||
52 | memcpy(buffer+5, data, len); | ||
53 | size = 5 + len; | ||
54 | d->next_frame = ALCATEL_ACK; | ||
55 | d->busy = true; | ||
56 | break; | ||
57 | case ALCATEL_ACK: | ||
58 | buffer[2] = d->in_counter; | ||
59 | if (d->in_counter == 0) d->in_counter = 1; | ||
60 | size = 3; | ||
61 | d->next_frame = ALCATEL_DATA; | ||
62 | break; | ||
63 | default: | ||
64 | /* In fact, other types probably can came just from mobile... */ | ||
65 | smprintf(s,"WARNING: Wanted to send some unknown packet (%02X)\n", type); | ||
66 | return ERR_NOTIMPLEMENTED; | ||
67 | } | ||
68 | |||
69 | /* Calculate packet checksum */ | ||
70 | for (i=0; i<size; i++) checksum ^= buffer[i]; | ||
71 | |||
72 | buffer[size] = checksum; | ||
73 | size ++; | ||
74 | |||
75 | GSM_DumpMessageLevel2(s, buffer, size, type); | ||
76 | GSM_DumpMessageLevel3(s, buffer, size, type); | ||
77 | while (sent != size ) { | ||
78 | if ((i = s->Device.Functions->WriteDevice(s,buffer + sent, size - sent)) == 0) { | ||
79 | return ERR_DEVICEWRITEERROR; | ||
80 | } | ||
81 | sent += i; | ||
82 | } | ||
83 | |||
84 | if (type == ALCATEL_CONNECT || type == ALCATEL_DISCONNECT) { | ||
85 | /* For connect and disconnect we need a bit larger delay */ | ||
86 | // my_sleep(10); | ||
87 | while (d->busy) { | ||
88 | GSM_ReadDevice(s,true); | ||
89 | my_sleep(1); | ||
90 | i++; | ||
91 | if (i == 10) return ERR_TIMEOUT; | ||
92 | } | ||
93 | } | ||
94 | return ERR_NONE; | ||
95 | } | ||
96 | |||
97 | static GSM_Error ALCABUS_StateMachine(GSM_StateMachine *s, unsigned char rx_char) | ||
98 | { | ||
99 | GSM_Protocol_ALCABUSData *d = &s->Protocol.Data.ALCABUS; | ||
100 | int i; | ||
101 | int checksum = 0; | ||
102 | |||
103 | if (d->Msg.BufferUsed < d->Msg.Length + 1) { | ||
104 | d->Msg.BufferUsed= d->Msg.Length + 1; | ||
105 | d->Msg.Buffer = (unsigned char *)realloc(d->Msg.Buffer,d->Msg.BufferUsed); | ||
106 | } | ||
107 | |||
108 | /* Check for header */ | ||
109 | if ((d->Msg.Length == 0) && (rx_char != ALCATEL_HEADER)) { | ||
110 | smprintf(s,"WARNING: Expecting alcatel header (%02X) but got (%02X)\n", ALCATEL_HEADER, rx_char); | ||
111 | return ERR_UNKNOWNRESPONSE; | ||
112 | /* Check for packet type */ | ||
113 | } else if (d->Msg.Length == 1){ | ||
114 | d->Msg.Type = rx_char; | ||
115 | /* Was it unexpected packet? */ | ||
116 | if ((rx_char != d->next_frame) && (rx_char != ALCATEL_CONTROL)) { | ||
117 | smprintf(s,"WARNING: Expecting alcatel packet type (%02X) but got (%02X)\n", d->next_frame, rx_char); | ||
118 | } | ||
119 | /* Determine packet size */ | ||
120 | switch (rx_char) { | ||
121 | case ALCATEL_ACK: | ||
122 | d->expected_size = 4; | ||
123 | break; | ||
124 | case ALCATEL_DATA: | ||
125 | /* Packet length is in it's header */ | ||
126 | d->expected_size = -1; | ||
127 | break; | ||
128 | case ALCATEL_CONTROL: | ||
129 | d->expected_size = 4; | ||
130 | break; | ||
131 | case ALCATEL_CONNECT_ACK: | ||
132 | d->expected_size = 6; | ||
133 | break; | ||
134 | case ALCATEL_DISCONNECT_ACK: | ||
135 | d->expected_size = 3; | ||
136 | break; | ||
137 | default: | ||
138 | smprintf(s,"WARNING: Something went wrong, unknown packet received (%02X)\n", rx_char); | ||
139 | return ERR_UNKNOWNRESPONSE; | ||
140 | } | ||
141 | /* Check counter, we can probably ignore error here ;-) */ | ||
142 | } else if ((d->Msg.Length == 2) && (d->Msg.Type == ALCATEL_DATA)) { | ||
143 | if (rx_char != d->in_counter) { | ||
144 | smprintf(s,"WARNING: Unexpected packet number, ignoring (expected %02X, received %02X)\n", d->in_counter, rx_char); | ||
145 | d->in_counter = rx_char; | ||
146 | } | ||
147 | /* Increase incoming packet counter */ | ||
148 | if (d->in_counter == ALCATEL_MAX_COUNTER) d->in_counter = 0; | ||
149 | else d->in_counter++; | ||
150 | /* Read size for data packet */ | ||
151 | } else if ((d->Msg.Length == 4) && (d->Msg.Type == ALCATEL_DATA)) { | ||
152 | /* Header till now + checksum */ | ||
153 | d->expected_size = (int)rx_char + 6; | ||
154 | } | ||
155 | |||
156 | /* Write received byte into buffer */ | ||
157 | d->Msg.Buffer[d->Msg.Length++] = rx_char; | ||
158 | |||
159 | /* Did we received whole packet? */ | ||
160 | if (d->expected_size == d->Msg.Length) { | ||
161 | /* Check checksum */ | ||
162 | for (i=0; i< (d->Msg.Length - 1); i++) checksum ^= d->Msg.Buffer[i]; | ||
163 | if (checksum != d->Msg.Buffer[d->Msg.Length - 1]) { | ||
164 | /* We can only warn, as we don't know what should happend now... */ | ||
165 | smprintf(s,"WARNING: Ignoring incorrect packet checksum!\n"); | ||
166 | } | ||
167 | |||
168 | /* Was it data? */ | ||
169 | if (d->Msg.Type == ALCATEL_DATA) { | ||
170 | /* Dispatch message */ | ||
171 | s->Phone.Data.RequestMsg= &d->Msg; | ||
172 | s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); | ||
173 | /* Send ack */ | ||
174 | ALCABUS_WriteMessage (s, 0, 0, ALCATEL_ACK); | ||
175 | /* Reset message length */ | ||
176 | d->Msg.Length = 0; | ||
177 | /* Was it ack? */ | ||
178 | } else if ((d->Msg.Type == ALCATEL_ACK) || | ||
179 | (d->Msg.Type == ALCATEL_CONTROL) || | ||
180 | (d->Msg.Type == ALCATEL_CONNECT_ACK) || | ||
181 | (d->Msg.Type == ALCATEL_DISCONNECT_ACK)) { | ||
182 | /* TODO: check counter of ack? */ | ||
183 | if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || | ||
184 | s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { | ||
185 | smprintf(s, "Received %s ack ", | ||
186 | (d->Msg.Type == ALCATEL_ACK) ? "normal" : | ||
187 | (d->Msg.Type == ALCATEL_CONTROL) ? "control" : | ||
188 | (d->Msg.Type == ALCATEL_CONNECT_ACK) ? "connect" : | ||
189 | (d->Msg.Type == ALCATEL_DISCONNECT_ACK) ? "disconnect" : | ||
190 | "BUG"); | ||
191 | smprintf(s, "0x%02x / 0x%04x", d->Msg.Type, d->Msg.Length); | ||
192 | DumpMessage(s->di.df, s->di.dl, d->Msg.Buffer, d->Msg.Length); | ||
193 | fflush(s->di.df); | ||
194 | } | ||
195 | if (s->di.dl==DL_BINARY) { | ||
196 | smprintf(s,"%c",0x02);/* Receiving */ | ||
197 | smprintf(s,"%c",d->Msg.Type); | ||
198 | smprintf(s,"%c",d->Msg.Length/256); | ||
199 | smprintf(s,"%c",d->Msg.Length%256); | ||
200 | for (i=0;i<d->Msg.Length;i++) smprintf(s,"%c",d->Msg.Buffer[i]); | ||
201 | } | ||
202 | if (d->Msg.Type != ALCATEL_CONTROL) { | ||
203 | d->next_frame = ALCATEL_DATA; | ||
204 | d->busy = false; | ||
205 | } | ||
206 | /* Reset message length */ | ||
207 | d->Msg.Length = 0; | ||
208 | } | ||
209 | |||
210 | /* Was it unexpected type? */ | ||
211 | if ((d->Msg.Type != d->next_frame) && (d->Msg.Type != ALCATEL_CONTROL)) { | ||
212 | return ERR_FRAMENOTREQUESTED; | ||
213 | } | ||
214 | } /* Last byte of packet */ | ||
215 | |||
216 | return ERR_NONE; | ||
217 | } | ||
218 | |||
219 | static GSM_Error ALCABUS_Initialise(GSM_StateMachine *s) | ||
220 | { | ||
221 | GSM_Protocol_ALCABUSData *d = &s->Protocol.Data.ALCABUS; | ||
222 | |||
223 | /* Initialise some variables */ | ||
224 | d->Msg.BufferUsed= 0; | ||
225 | d->Msg.Buffer = NULL; | ||
226 | d->Msg.Length = 0; | ||
227 | d->Msg.Type = 0; | ||
228 | d->in_counter = 1; | ||
229 | d->out_counter = 0; | ||
230 | d->busy = false; | ||
231 | |||
232 | /* Initialise protocol */ | ||
233 | dbgprintf ("Initializing binary mode\n"); | ||
234 | return ALCABUS_WriteMessage (s, 0, 0, ALCATEL_CONNECT); | ||
235 | } | ||
236 | |||
237 | static GSM_Error ALCABUS_Terminate(GSM_StateMachine *s) | ||
238 | { | ||
239 | /* Terminate protocol */ | ||
240 | dbgprintf ("Closing binary mode\n"); | ||
241 | return ALCABUS_WriteMessage (s, 0, 0, ALCATEL_DISCONNECT); | ||
242 | } | ||
243 | |||
244 | GSM_Protocol_Functions ALCABUSProtocol = { | ||
245 | ALCABUS_WriteMessage, | ||
246 | ALCABUS_StateMachine, | ||
247 | ALCABUS_Initialise, | ||
248 | ALCABUS_Terminate | ||
249 | }; | ||
250 | |||
251 | #endif | ||
252 | |||
253 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
254 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
255 | */ | ||
diff --git a/gammu/emb/common/protocol/alcatel/alcabus.h b/gammu/emb/common/protocol/alcatel/alcabus.h new file mode 100644 index 0000000..3b9b44e --- a/dev/null +++ b/gammu/emb/common/protocol/alcatel/alcabus.h | |||
@@ -0,0 +1,61 @@ | |||
1 | /* (c) 2002-2003 by Michal Cihar */ | ||
2 | /* | ||
3 | * Low level functions for communication with Alcatel One Touch phones. | ||
4 | * | ||
5 | * This code implements the protocol used for synchronisation with PC. | ||
6 | */ | ||
7 | |||
8 | #ifndef alcabus_h | ||
9 | #define alcabus_h | ||
10 | |||
11 | #include "../protocol.h" | ||
12 | |||
13 | #define ALCATEL_HEADER 0x7E | ||
14 | |||
15 | /* packet types: */ | ||
16 | /* used for starting binary connection (must be preceeded by | ||
17 | * AT+CPROT=16,"V1.0",16 and phone should response to it by CONNECT_ACK) | ||
18 | */ | ||
19 | #define ALCATEL_CONNECT 0x0A | ||
20 | /* received when connect suceeded */ | ||
21 | #define ALCATEL_CONNECT_ACK 0x0C | ||
22 | /* used for stopping binary connection */ | ||
23 | #define ALCATEL_DISCONNECT 0x0D | ||
24 | /* received when binnary connection ends */ | ||
25 | #define ALCATEL_DISCONNECT_ACK 0x0E | ||
26 | /* some control ack, I really don't know what should it do, so currently it | ||
27 | * is just ignored. It comes time to time, and communication continues OK also | ||
28 | * if no reply was made. */ | ||
29 | #define ALCATEL_CONTROL 0x0F | ||
30 | /* sending/recieving data */ | ||
31 | #define ALCATEL_DATA 0x02 | ||
32 | /* acknowledge to data */ | ||
33 | #define ALCATEL_ACK 0x06 | ||
34 | |||
35 | /* Maximal value for packet counter */ | ||
36 | #define ALCATEL_MAX_COUNTER 0x3D | ||
37 | |||
38 | typedef struct { | ||
39 | GSM_Protocol_Message Msg; | ||
40 | /* Incoming packets ID counter */ | ||
41 | int in_counter; | ||
42 | /* Outgoing packets ID counter */ | ||
43 | int out_counter; | ||
44 | /* Expected size of incoming packet */ | ||
45 | int expected_size; | ||
46 | /* What is type of frame we expect next */ | ||
47 | unsigned char next_frame; | ||
48 | /* State of mobile, if we expect something (generally some ack) we set | ||
49 | * this to true and no other action can be performed until it is false. */ | ||
50 | bool busy; | ||
51 | } GSM_Protocol_ALCABUSData; | ||
52 | |||
53 | #ifndef GSM_USED_SERIALDEVICE | ||
54 | # define GSM_USED_SERIALDEVICE | ||
55 | #endif | ||
56 | |||
57 | #endif | ||
58 | |||
59 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
60 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
61 | */ | ||
diff --git a/gammu/emb/common/protocol/at/at.c b/gammu/emb/common/protocol/at/at.c new file mode 100644 index 0000000..f4a75b7 --- a/dev/null +++ b/gammu/emb/common/protocol/at/at.c | |||
@@ -0,0 +1,229 @@ | |||
1 | /* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */ | ||
2 | |||
3 | #include "../../gsmstate.h" | ||
4 | |||
5 | #if defined(GSM_ENABLE_AT) || defined(GSM_ENABLE_BLUEAT) || defined(GSM_ENABLE_IRDAAT) | ||
6 | |||
7 | #include <stdio.h> | ||
8 | #include <string.h> | ||
9 | |||
10 | #include "../../gsmcomon.h" | ||
11 | #include "at.h" | ||
12 | |||
13 | static GSM_Error AT_WriteMessage (GSM_StateMachine *s, unsigned char *buffer, | ||
14 | int length, unsigned char type) | ||
15 | { | ||
16 | int i,sent = 0; | ||
17 | |||
18 | GSM_DumpMessageLevel2(s, buffer, length, type); | ||
19 | GSM_DumpMessageLevel3(s, buffer, length, type); | ||
20 | if (s->Protocol.Data.AT.FastWrite) { | ||
21 | while (sent != length) { | ||
22 | if ((i = s->Device.Functions->WriteDevice(s,buffer + sent, length - sent)) == 0) { | ||
23 | return ERR_DEVICEWRITEERROR; | ||
24 | } | ||
25 | sent += i; | ||
26 | } | ||
27 | } else { | ||
28 | for (i=0;i<length;i++) { | ||
29 | if (s->Device.Functions->WriteDevice(s,buffer+i,1)!=1) return ERR_DEVICEWRITEERROR; | ||
30 | /* For some phones like Siemens M20 we need to wait a little | ||
31 | * after writing each char. Possible reason: these phones | ||
32 | * can't receive so fast chars or there is bug here in Gammu */ | ||
33 | my_sleep(1); | ||
34 | } | ||
35 | my_sleep(400); | ||
36 | } | ||
37 | |||
38 | return ERR_NONE; | ||
39 | } | ||
40 | |||
41 | typedef struct { | ||
42 | char*text; | ||
43 | intlines; | ||
44 | } SpecialAnswersStruct; | ||
45 | |||
46 | static GSM_Error AT_StateMachine(GSM_StateMachine *s, unsigned char rx_char) | ||
47 | { | ||
48 | GSM_Protocol_Message Msg2; | ||
49 | GSM_Protocol_ATData *d = &s->Protocol.Data.AT; | ||
50 | int i; | ||
51 | |||
52 | /* These are lines with end of "normal" answers */ | ||
53 | static char *StartStrings[] = { | ||
54 | "OK" , "ERROR" , | ||
55 | "+CME ERROR:" , "+CMS ERROR:", | ||
56 | |||
57 | "+CPIN: " ,/*A2D issue*/ | ||
58 | |||
59 | NULL}; | ||
60 | |||
61 | /* Some info from phone can be inside "normal" answers | ||
62 | * It starts with strings written here | ||
63 | */ | ||
64 | static SpecialAnswersStructSpecialAnswers[] = { | ||
65 | {"_OSIGQ:" ,1}, {"_OBS:",1}, | ||
66 | {"^SCN:" ,1}, {"+CGREG:",1}, | ||
67 | {"+CBM:" ,1}, {"+CMT:",2}, | ||
68 | {"+CMTI:" ,1}, {"+CDS:",2}, | ||
69 | {"+CREG:",1}, | ||
70 | |||
71 | {"RING" ,1}, {"NO CARRIER",1}, | ||
72 | {"NO ANSWER" ,1}, {"+COLP",1}, | ||
73 | {"+CLIP",1}, | ||
74 | |||
75 | {NULL ,1}}; | ||
76 | |||
77 | /* Ignore leading CR, LF and ESC */ | ||
78 | if (d->Msg.Length == 0) { | ||
79 | if (rx_char == 10 || rx_char == 13 || rx_char == 27) return ERR_NONE; | ||
80 | d->LineStart = d->Msg.Length; | ||
81 | } | ||
82 | |||
83 | if (d->Msg.BufferUsed < d->Msg.Length + 2) { | ||
84 | d->Msg.BufferUsed= d->Msg.Length + 2; | ||
85 | d->Msg.Buffer = (unsigned char *)realloc(d->Msg.Buffer,d->Msg.BufferUsed); | ||
86 | } | ||
87 | d->Msg.Buffer[d->Msg.Length++] = rx_char; | ||
88 | d->Msg.Buffer[d->Msg.Length ] = 0; | ||
89 | |||
90 | switch (rx_char) { | ||
91 | case 0: | ||
92 | break; | ||
93 | case 10: | ||
94 | case 13: | ||
95 | if (!d->wascrlf) d->LineEnd = d->Msg.Length-1; | ||
96 | d->wascrlf = true; | ||
97 | if (d->Msg.Length > 0 && rx_char == 10 && d->Msg.Buffer[d->Msg.Length-2]==13) { | ||
98 | i = 0; | ||
99 | while (StartStrings[i] != NULL) { | ||
100 | if (strncmp(StartStrings[i],d->Msg.Buffer+d->LineStart,strlen(StartStrings[i])) == 0) { | ||
101 | s->Phone.Data.RequestMsg= &d->Msg; | ||
102 | s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); | ||
103 | d->Msg.Length = 0; | ||
104 | break; | ||
105 | } | ||
106 | i++; | ||
107 | } | ||
108 | if (d->Msg.Length == 0) break; | ||
109 | |||
110 | i = 0; | ||
111 | while (SpecialAnswers[i].text != NULL) { | ||
112 | if (strncmp(SpecialAnswers[i].text,d->Msg.Buffer+d->LineStart,strlen(SpecialAnswers[i].text)) == 0) { | ||
113 | /* We need something better here */ | ||
114 | if (s->Phone.Data.RequestID == ID_GetNetworkInfo && strncmp(SpecialAnswers[i].text,"+CREG:",6) == 0) { | ||
115 | i++; | ||
116 | continue; | ||
117 | } | ||
118 | d->SpecialAnswerStart = d->LineStart; | ||
119 | d->SpecialAnswerLines= SpecialAnswers[i].lines; | ||
120 | } | ||
121 | i++; | ||
122 | } | ||
123 | |||
124 | |||
125 | if (d->SpecialAnswerLines == 1) { | ||
126 | /* This is end of special answer. We copy it and send to phone module */ | ||
127 | Msg2.Buffer = malloc(d->LineEnd - d->SpecialAnswerStart + 3); | ||
128 | memcpy(Msg2.Buffer,d->Msg.Buffer+d->SpecialAnswerStart,d->LineEnd - d->SpecialAnswerStart + 2); | ||
129 | Msg2.Length = d->LineEnd - d->SpecialAnswerStart + 2; | ||
130 | Msg2.Buffer[Msg2.Length] = 0; | ||
131 | |||
132 | s->Phone.Data.RequestMsg= &Msg2; | ||
133 | s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); | ||
134 | free(Msg2.Buffer); | ||
135 | |||
136 | /* We cut special answer from main buffer */ | ||
137 | d->Msg.Length = d->SpecialAnswerStart; | ||
138 | if (d->Msg.Length != 0) d->Msg.Length = d->Msg.Length - 2; | ||
139 | |||
140 | /* We need to find earlier values of all variables */ | ||
141 | d->wascrlf = false; | ||
142 | d->LineStart = 0; | ||
143 | for (i=0;i<d->Msg.Length;i++) { | ||
144 | switch(d->Msg.Buffer[i]) { | ||
145 | case 0: | ||
146 | break; | ||
147 | case 10: | ||
148 | case 13: | ||
149 | if (!d->wascrlf) d->LineEnd = d->Msg.Length-1; | ||
150 | d->wascrlf = true; | ||
151 | break; | ||
152 | default: | ||
153 | if (d->wascrlf) { | ||
154 | d->LineStart= d->Msg.Length-1; | ||
155 | d->wascrlf = false; | ||
156 | } | ||
157 | } | ||
158 | } | ||
159 | d->Msg.Buffer[d->Msg.Length] = 0; | ||
160 | } | ||
161 | if (d->SpecialAnswerLines > 0) d->SpecialAnswerLines--; | ||
162 | } | ||
163 | break; | ||
164 | case 'T': | ||
165 | /* When CONNECT string received, we know there will not follow | ||
166 | * anything AT related, after CONNECT can follow ppp data, alcabus | ||
167 | * data and also other things. | ||
168 | */ | ||
169 | if (strncmp(d->Msg.Buffer+d->LineStart, "CONNECT", 7) == 0) { | ||
170 | s->Phone.Data.RequestMsg = &d->Msg; | ||
171 | s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); | ||
172 | d->LineStart = -1; | ||
173 | d->Msg.Length = 0; | ||
174 | break; | ||
175 | } | ||
176 | default: | ||
177 | if (d->wascrlf) { | ||
178 | d->LineStart= d->Msg.Length-1; | ||
179 | d->wascrlf = false; | ||
180 | } | ||
181 | if (d->EditMode) { | ||
182 | if (strlen(d->Msg.Buffer+d->LineStart) == 2 && strncmp(d->Msg.Buffer+d->LineStart,"> ",2)==0) { | ||
183 | s->Phone.Data.RequestMsg= &d->Msg; | ||
184 | s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); | ||
185 | } | ||
186 | } | ||
187 | } | ||
188 | return ERR_NONE; | ||
189 | } | ||
190 | |||
191 | static GSM_Error AT_Initialise(GSM_StateMachine *s) | ||
192 | { | ||
193 | GSM_Protocol_ATData *d = &s->Protocol.Data.AT; | ||
194 | |||
195 | d->Msg.Buffer = NULL; | ||
196 | d->Msg.BufferUsed= 0; | ||
197 | d->Msg.Length = 0; | ||
198 | d->Msg.Type = 0; | ||
199 | |||
200 | d->SpecialAnswerLines= 0; | ||
201 | d->LineStart = -1; | ||
202 | d->LineEnd = -1; | ||
203 | d->wascrlf = false; | ||
204 | d->EditMode = false; | ||
205 | d->FastWrite = false; | ||
206 | |||
207 | s->Device.Functions->DeviceSetDtrRts(s,true,true); | ||
208 | |||
209 | return s->Device.Functions->DeviceSetSpeed(s,s->Speed); | ||
210 | } | ||
211 | |||
212 | static GSM_Error AT_Terminate(GSM_StateMachine *s) | ||
213 | { | ||
214 | free(s->Protocol.Data.AT.Msg.Buffer); | ||
215 | return ERR_NONE; | ||
216 | } | ||
217 | |||
218 | GSM_Protocol_Functions ATProtocol = { | ||
219 | AT_WriteMessage, | ||
220 | AT_StateMachine, | ||
221 | AT_Initialise, | ||
222 | AT_Terminate | ||
223 | }; | ||
224 | |||
225 | #endif | ||
226 | |||
227 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
228 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
229 | */ | ||
diff --git a/gammu/emb/common/protocol/at/at.h b/gammu/emb/common/protocol/at/at.h new file mode 100644 index 0000000..e200646 --- a/dev/null +++ b/gammu/emb/common/protocol/at/at.h | |||
@@ -0,0 +1,36 @@ | |||
1 | /* (c) 2002-2003 by Marcin Wiacek and Michal Cihar */ | ||
2 | |||
3 | #ifndef at_h | ||
4 | #define at_h | ||
5 | |||
6 | #include "../protocol.h" | ||
7 | |||
8 | typedef struct { | ||
9 | GSM_Protocol_Message Msg; | ||
10 | bool wascrlf; | ||
11 | int LineStart,LineEnd; | ||
12 | int SpecialAnswerLines,SpecialAnswerStart; | ||
13 | |||
14 | bool EditMode;/* wait for modem answer or not */ | ||
15 | bool FastWrite; | ||
16 | } GSM_Protocol_ATData; | ||
17 | |||
18 | #ifndef GSM_USED_SERIALDEVICE | ||
19 | # define GSM_USED_SERIALDEVICE | ||
20 | #endif | ||
21 | #if defined(GSM_ENABLE_BLUEAT) | ||
22 | # ifndef GSM_USED_BLUETOOTHDEVICE | ||
23 | # define GSM_USED_BLUETOOTHDEVICE | ||
24 | # endif | ||
25 | #endif | ||
26 | #if defined(GSM_ENABLE_IRDAAT) | ||
27 | # ifndef GSM_USED_IRDADEVICE | ||
28 | # define GSM_USED_IRDADEVICE | ||
29 | # endif | ||
30 | #endif | ||
31 | |||
32 | #endif | ||
33 | |||
34 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
35 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
36 | */ | ||
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 | */ | ||
diff --git a/gammu/emb/common/protocol/obex/obex.c b/gammu/emb/common/protocol/obex/obex.c new file mode 100644 index 0000000..942c084 --- a/dev/null +++ b/gammu/emb/common/protocol/obex/obex.c | |||
@@ -0,0 +1,120 @@ | |||
1 | /* (c) 2003 by Marcin Wiacek */ | ||
2 | /* www.irda.org OBEX specs 1.3 */ | ||
3 | |||
4 | #include "../../gsmstate.h" | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <string.h> | ||
8 | |||
9 | #if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) | ||
10 | |||
11 | #include "../../gsmcomon.h" | ||
12 | #include "obex.h" | ||
13 | |||
14 | static GSM_Error OBEX_WriteMessage (GSM_StateMachine *s, unsigned char *buffer, | ||
15 | int length, unsigned char type) | ||
16 | { | ||
17 | unsigned char*out_buffer; | ||
18 | int current=0,sent; | ||
19 | |||
20 | out_buffer = (unsigned char *)malloc(length + 3); | ||
21 | |||
22 | OBEXAddBlock(out_buffer, ¤t, type, buffer, length); | ||
23 | |||
24 | GSM_DumpMessageLevel2(s, out_buffer+3, length, type); | ||
25 | GSM_DumpMessageLevel3(s, out_buffer+3, length, type); | ||
26 | |||
27 | /* Send it out... */ | ||
28 | sent = s->Device.Functions->WriteDevice(s,out_buffer,current); | ||
29 | |||
30 | free(out_buffer); | ||
31 | |||
32 | if (sent!=current) return ERR_DEVICEWRITEERROR; | ||
33 | return ERR_NONE; | ||
34 | } | ||
35 | |||
36 | static GSM_Error OBEX_StateMachine(GSM_StateMachine *s, unsigned char rx_char) | ||
37 | { | ||
38 | GSM_Phone_Functions *Phone= s->Phone.Functions; | ||
39 | GSM_Protocol_OBEXData *d= &s->Protocol.Data.OBEX; | ||
40 | |||
41 | switch (d->MsgRXState) { | ||
42 | case RX_Sync: | ||
43 | d->Msg.Type = rx_char; | ||
44 | d->MsgRXState = RX_GetLength1; | ||
45 | break; | ||
46 | case RX_GetLength1: | ||
47 | d->Msg.Length = rx_char * 256; | ||
48 | d->MsgRXState = RX_GetLength2; | ||
49 | break; | ||
50 | case RX_GetLength2: | ||
51 | d->Msg.Length = d->Msg.Length + rx_char - 3; | ||
52 | d->Msg.Count = 0; | ||
53 | if (d->Msg.Count == d->Msg.Length) { | ||
54 | s->Phone.Data.RequestMsg= &d->Msg; | ||
55 | s->Phone.Data.DispatchError= Phone->DispatchMessage(s); | ||
56 | d->MsgRXState = RX_Sync; | ||
57 | } else { | ||
58 | if (d->Msg.BufferUsed < d->Msg.Length) { | ||
59 | d->Msg.BufferUsed = d->Msg.Length; | ||
60 | d->Msg.Buffer = (unsigned char *)realloc(d->Msg.Buffer,d->Msg.BufferUsed); | ||
61 | } | ||
62 | d->MsgRXState = RX_GetMessage; | ||
63 | } | ||
64 | break; | ||
65 | case RX_GetMessage: | ||
66 | d->Msg.Buffer[d->Msg.Count] = rx_char; | ||
67 | d->Msg.Count++; | ||
68 | if (d->Msg.Count == d->Msg.Length) { | ||
69 | s->Phone.Data.RequestMsg= &d->Msg; | ||
70 | s->Phone.Data.DispatchError= Phone->DispatchMessage(s); | ||
71 | d->MsgRXState = RX_Sync; | ||
72 | } | ||
73 | break; | ||
74 | } | ||
75 | |||
76 | return ERR_NONE; | ||
77 | } | ||
78 | |||
79 | static GSM_Error OBEX_Initialise(GSM_StateMachine *s) | ||
80 | { | ||
81 | GSM_Protocol_OBEXData *d = &s->Protocol.Data.OBEX; | ||
82 | |||
83 | d->Msg.BufferUsed= 0; | ||
84 | d->Msg.Buffer = NULL; | ||
85 | d->Msg.Length = 0; | ||
86 | |||
87 | d->MsgRXState = RX_Sync; | ||
88 | |||
89 | return ERR_NONE; | ||
90 | } | ||
91 | |||
92 | static GSM_Error OBEX_Terminate(GSM_StateMachine *s) | ||
93 | { | ||
94 | free(s->Protocol.Data.OBEX.Msg.Buffer); | ||
95 | return ERR_NONE; | ||
96 | } | ||
97 | |||
98 | GSM_Protocol_Functions OBEXProtocol = { | ||
99 | OBEX_WriteMessage, | ||
100 | OBEX_StateMachine, | ||
101 | OBEX_Initialise, | ||
102 | OBEX_Terminate | ||
103 | }; | ||
104 | |||
105 | #endif | ||
106 | |||
107 | void OBEXAddBlock(char *Buffer, int *Pos, unsigned char ID, char *AddBuffer, int AddLength) | ||
108 | { | ||
109 | Buffer[(*Pos)++] = ID; | ||
110 | Buffer[(*Pos)++] = (AddLength+3)/256; | ||
111 | Buffer[(*Pos)++] = (AddLength+3)%256; | ||
112 | if (AddBuffer != NULL) { | ||
113 | memcpy(Buffer+(*Pos),AddBuffer,AddLength); | ||
114 | (*Pos) += AddLength; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
119 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
120 | */ | ||
diff --git a/gammu/emb/common/protocol/obex/obex.h b/gammu/emb/common/protocol/obex/obex.h new file mode 100644 index 0000000..0e927c7 --- a/dev/null +++ b/gammu/emb/common/protocol/obex/obex.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /* (c) 2003 by Marcin Wiacek */ | ||
2 | |||
3 | #ifndef obex_h | ||
4 | #define obex_h | ||
5 | |||
6 | #include "../protocol.h" | ||
7 | |||
8 | typedef struct { | ||
9 | int MsgRXState; | ||
10 | GSM_Protocol_Message Msg; | ||
11 | } GSM_Protocol_OBEXData; | ||
12 | |||
13 | #ifndef GSM_USED_SERIALDEVICE | ||
14 | # define GSM_USED_SERIALDEVICE | ||
15 | #endif | ||
16 | #if defined(GSM_ENABLE_BLUEOBEX) | ||
17 | # ifndef GSM_USED_BLUETOOTHDEVICE | ||
18 | # define GSM_USED_BLUETOOTHDEVICE | ||
19 | # endif | ||
20 | #endif | ||
21 | #if defined(GSM_ENABLE_IRDAOBEX) | ||
22 | # ifndef GSM_USED_IRDADEVICE | ||
23 | # define GSM_USED_IRDADEVICE | ||
24 | # endif | ||
25 | #endif | ||
26 | |||
27 | void OBEXAddBlock(char *Buffer, int *Pos, unsigned char ID, char *AddBuffer, int AddLength); | ||
28 | |||
29 | #endif | ||
30 | |||
31 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
32 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
33 | */ | ||
diff --git a/gammu/emb/common/protocol/protocol.h b/gammu/emb/common/protocol/protocol.h new file mode 100644 index 0000000..f8e1fe5 --- a/dev/null +++ b/gammu/emb/common/protocol/protocol.h | |||
@@ -0,0 +1,31 @@ | |||
1 | /* (c) 2002-2003 by Marcin Wiacek */ | ||
2 | |||
3 | #ifndef protocol_common_h | ||
4 | #define protocol_common_h | ||
5 | |||
6 | typedef enum { | ||
7 | RX_Sync, | ||
8 | RX_GetDestination, | ||
9 | RX_GetSource, | ||
10 | RX_GetType, | ||
11 | RX_GetLength1, | ||
12 | RX_GetLength2, | ||
13 | RX_GetMessage | ||
14 | } GSM_Protocol_RXState; | ||
15 | |||
16 | typedef struct { | ||
17 | int Length; | ||
18 | int Count; | ||
19 | unsigned char Type; | ||
20 | unsigned char Source; | ||
21 | unsigned char Destination; | ||
22 | unsigned char*Buffer; | ||
23 | int BufferUsed; | ||
24 | unsigned char CheckSum[2]; | ||
25 | } GSM_Protocol_Message; | ||
26 | |||
27 | #endif | ||
28 | |||
29 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
30 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
31 | */ | ||
diff --git a/gammu/emb/common/protocol/symbian/mrouter.c b/gammu/emb/common/protocol/symbian/mrouter.c new file mode 100644 index 0000000..2ca7af1 --- a/dev/null +++ b/gammu/emb/common/protocol/symbian/mrouter.c | |||
@@ -0,0 +1,110 @@ | |||
1 | /* (c) 2003 by Marcin Wiacek */ | ||
2 | |||
3 | #include "../../gsmstate.h" | ||
4 | |||
5 | #if defined(GSM_ENABLE_MROUTERBLUE) | ||
6 | |||
7 | #include <stdio.h> | ||
8 | #include <string.h> | ||
9 | |||
10 | #include "../../gsmcomon.h" | ||
11 | #include "mrouter.h" | ||
12 | |||
13 | static GSM_Error MROUTER_WriteMessage (GSM_StateMachine *s, unsigned char *buffer, | ||
14 | int length, unsigned char type) | ||
15 | { | ||
16 | unsigned char*out_buffer; | ||
17 | int current=0,sent; | ||
18 | |||
19 | out_buffer = (unsigned char *)malloc(length+1); | ||
20 | |||
21 | memcpy(out_buffer,buffer,length); | ||
22 | out_buffer[length]=0x7E; | ||
23 | |||
24 | GSM_DumpMessageLevel2(s, out_buffer, length, type); | ||
25 | GSM_DumpMessageLevel3(s, out_buffer, length, type); | ||
26 | |||
27 | /* Send it out... */ | ||
28 | sent = s->Device.Functions->WriteDevice(s,out_buffer,length+1); | ||
29 | |||
30 | free(out_buffer); | ||
31 | |||
32 | if (sent!=current) return ERR_DEVICEWRITEERROR; | ||
33 | return ERR_NONE; | ||
34 | } | ||
35 | |||
36 | static GSM_Error MROUTER_StateMachine(GSM_StateMachine *s, unsigned char rx_char) | ||
37 | { | ||
38 | GSM_Phone_Functions *Phone= s->Phone.Functions; | ||
39 | GSM_Protocol_MROUTERData *d= &s->Protocol.Data.MROUTER; | ||
40 | |||
41 | switch (d->MsgRXState) { | ||
42 | case RX_Sync: | ||
43 | if (rx_char == 0x7E) { | ||
44 | d->MsgRXState = RX_GetMessage; | ||
45 | d->Msg.Count = 0; | ||
46 | d->Msg.Length = 0; | ||
47 | } else smprintf(s,"Sync error: %02x\n",rx_char); | ||
48 | break; | ||
49 | case RX_GetMessage: | ||
50 | if (rx_char == 0x7E) { | ||
51 | s->Phone.Data.RequestMsg= &d->Msg; | ||
52 | s->Phone.Data.DispatchError= Phone->DispatchMessage(s); | ||
53 | d->Msg.Count = 0; | ||
54 | d->Msg.Length = 0; | ||
55 | } else { | ||
56 | d->Msg.BufferUsed = d->Msg.Length+1; | ||
57 | d->Msg.Buffer = (unsigned char *)realloc(d->Msg.Buffer,d->Msg.BufferUsed); | ||
58 | |||
59 | d->Msg.Buffer[d->Msg.Count] = rx_char; | ||
60 | d->Msg.Count++; | ||
61 | d->Msg.Length++; | ||
62 | } | ||
63 | break; | ||
64 | } | ||
65 | |||
66 | return ERR_NONE; | ||
67 | } | ||
68 | |||
69 | static GSM_Error MROUTER_Initialise(GSM_StateMachine *s) | ||
70 | { | ||
71 | GSM_Protocol_MROUTERData *d = &s->Protocol.Data.MROUTER; | ||
72 | GSM_Error error; | ||
73 | |||
74 | d->Msg.BufferUsed= 0; | ||
75 | d->Msg.Buffer = NULL; | ||
76 | d->Msg.Length = 0; | ||
77 | |||
78 | d->MsgRXState = RX_Sync; | ||
79 | |||
80 | //error=s->Device.Functions->DeviceSetDtrRts(s,false,false); | ||
81 | // if (error!=ERR_NONE) return error; | ||
82 | |||
83 | error=s->Device.Functions->DeviceSetSpeed(s,115200); | ||
84 | if (error!=ERR_NONE) return error; | ||
85 | |||
86 | |||
87 | //error=s->Device.Functions->DeviceSetSpeed(s,115200); | ||
88 | // if (error!=ERR_NONE) return error; | ||
89 | |||
90 | return ERR_NONE; | ||
91 | } | ||
92 | |||
93 | static GSM_Error MROUTER_Terminate(GSM_StateMachine *s) | ||
94 | { | ||
95 | free(s->Protocol.Data.MROUTER.Msg.Buffer); | ||
96 | return ERR_NONE; | ||
97 | } | ||
98 | |||
99 | GSM_Protocol_Functions MROUTERProtocol = { | ||
100 | MROUTER_WriteMessage, | ||
101 | MROUTER_StateMachine, | ||
102 | MROUTER_Initialise, | ||
103 | MROUTER_Terminate | ||
104 | }; | ||
105 | |||
106 | #endif | ||
107 | |||
108 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
109 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
110 | */ | ||
diff --git a/gammu/emb/common/protocol/symbian/mrouter.h b/gammu/emb/common/protocol/symbian/mrouter.h new file mode 100644 index 0000000..7d72cdd --- a/dev/null +++ b/gammu/emb/common/protocol/symbian/mrouter.h | |||
@@ -0,0 +1,31 @@ | |||
1 | /* (c) 2003 by Marcin Wiacek */ | ||
2 | |||
3 | #ifndef mrouter_h | ||
4 | #define mrouter_h | ||
5 | |||
6 | #include "../protocol.h" | ||
7 | |||
8 | typedef struct { | ||
9 | int MsgRXState; | ||
10 | GSM_Protocol_Message Msg; | ||
11 | } GSM_Protocol_MROUTERData; | ||
12 | |||
13 | #ifndef GSM_USED_SERIALDEVICE | ||
14 | # define GSM_USED_SERIALDEVICE | ||
15 | #endif | ||
16 | //#if defined(GSM_ENABLE_BLUEOBEX) | ||
17 | //# ifndef GSM_USED_BLUETOOTHDEVICE | ||
18 | //# define GSM_USED_BLUETOOTHDEVICE | ||
19 | //# endif | ||
20 | //#endif | ||
21 | //#if defined(GSM_ENABLE_IRDAOBEX) | ||
22 | //# ifndef GSM_USED_IRDADEVICE | ||
23 | //# define GSM_USED_IRDADEVICE | ||
24 | //# endif | ||
25 | //#endif | ||
26 | |||
27 | #endif | ||
28 | |||
29 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
30 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
31 | */ | ||