7 A Linux/Unix toolset and driver for mobile phones.
9 Copyright 2001 Manfred Jonsson <manfred.jonsson@gmx.de>
11 Released under the terms of the GNU GPL, see file COPYING for more details.
14 Revision 1.1.1.2 2002/04/03 00:08:07 short
15 Found in "gnokii-working" directory, some November-patches version
17 Revision 1.4 2001/09/09 21:45:49 machek
18 Cleanups from Ladislav Michl <ladis@psi.cz>:
20 *) do *not* internationalize debug messages
22 *) some whitespace fixes, do not use //
24 *) break is unneccessary after return
26 Revision 1.3 2001/08/20 23:27:37 pkot
27 Add hardware shakehand to the link layer (Manfred Jonsson)
29 Revision 1.2 2001/08/09 11:51:39 pkot
30 Generic AT support updates and cleanup (Manfred Jonsson)
32 Revision 1.1 2001/07/27 00:02:21 pkot
33 Generic AT support for the new structure (Manfred Jonsson)
37 /* System header files */
43 /* Various header file */
49 #include "gsm-common.h"
50 #include "gsm-ringtones.h"
51 #include "gsm-networks.h"
53 #include "links/utils.h"
54 #include "gsm-statemachine.h"
57 #include "links/atbus.h"
59 /* FIXME - pass device_* the link stuff?? */
60 /* FIXME - win32 stuff! */
64 static GSM_Link *glink;
65 static GSM_Statemachine *statemachine;
66 static int binlength = 0;
67 static char reply_buf[1024];
68 static int reply_buf_pos = 0;
71 static int xwrite(unsigned char *d, int len)
75 res = device_write(d, len);
77 if (errno != EAGAIN) {
78 perror("gnokii I/O error ");
91 AT_SendMessage(u16 message_length, u8 message_type, void *msg)
94 xwrite((char*)msg, message_length);
99 /* RX_State machine for receive handling. Called once for each character
100 received from the phone. */
101 void ATBUS_RX_StateMachine(unsigned char rx_char)
103 reply_buf[reply_buf_pos++] = rx_char;
104 reply_buf[reply_buf_pos] = '\0';
106 if (reply_buf_pos >= binlength) {
107 if (((reply_buf_pos > 3) && (!strncmp(reply_buf+reply_buf_pos-4, "OK\r\n", 4)))
108 || ((reply_buf_pos > 6) && (!strncmp(reply_buf+reply_buf_pos-7, "ERROR\r\n", 7)))) {
109 SM_IncomingFunction(statemachine, 1, reply_buf, reply_buf_pos);
114 /* needed for binary date etc
115 TODO: correct reading of variable length integers
116 if (reply_buf_pos == 12) {
117 if (!strncmp(reply_buf + 3, "ABC", 3) {
118 binlength = atoi(reply_buf + 8);
126 bool ATBUS_OpenSerial(int hw_handshake)
129 result = device_open(glink->PortDevice, false, false, hw_handshake, GCT_Serial);
131 perror(_("Couldn't open ATBUS device"));
134 device_changespeed(19200);
136 device_setdtrrts(0, 1);
138 device_setdtrrts(1, 1);
139 /* make 7110 happy */
142 device_setdtrrts(0, 0);
147 GSM_Error ATBUS_Loop(struct timeval *timeout)
149 unsigned char buffer[255];
152 res = device_select(timeout);
154 res = device_read(buffer, 255);
155 for (count = 0; count < res; count++)
156 ATBUS_RX_StateMachine(buffer[count]);
159 /* This traps errors from device_read */
163 return GE_INTERNALERROR;
167 /* Initialise variables and start the link */
168 GSM_Error ATBUS_Initialise(GSM_Statemachine *state, int hw_handshake)
170 setvbuf(stdout, NULL, _IONBF, 0);
171 setvbuf(stderr, NULL, _IONBF, 0);
173 /* 'Copy in' the global structures */
174 glink = &(state->Link);
175 statemachine = state;
177 /* Fill in the link functions */
178 glink->Loop = &ATBUS_Loop;
179 glink->SendMessage = &AT_SendMessage;
181 if (glink->ConnectionType == GCT_Serial) {
182 if (!ATBUS_OpenSerial(hw_handshake))
183 return GE_DEVICEOPENFAILED;
185 fprintf(stderr, "Device not supported by ATBUS");
186 return GE_DEVICEOPENFAILED;