This commit was generated by cvs2svn to compensate for changes in r158,
[gnokii.git] / common / phones / dc2711.c
1 /*
2
3   $Id$
4
5   G N O K I I
6
7   A Linux/Unix toolset and driver for Nokia mobile phones.
8
9   Copyright 2001 Pavel Machek <pavel@ucw.cz>
10
11   Released under the terms of the GNU GPL, see file COPYING for more details.
12
13   This file provides functions specific to the dancall 2711.
14   See README for more details on supported mobile phones.
15
16   $Log$
17   Revision 1.1.1.2  2002/04/03 00:08:08  short
18   Found in "gnokii-working" directory, some November-patches version
19
20   Revision 1.5  2001/07/27 00:02:21  pkot
21   Generic AT support for the new structure (Manfred Jonsson)
22
23   Revision 1.4  2001/04/25 12:53:07  machek
24   Added error handling to SMS receive function.
25
26   Revision 1.3  2001/03/23 13:40:23  chris
27   Pavel's patch and a few fixes.
28
29   Revision 1.2  2001/03/13 01:24:03  pkot
30   Code cleanup - no warnings during compilation
31
32   Revision 1.1  2001/03/11 11:26:15  machek
33   Dancall support, now actually works enough to get sms messages.
34
35
36 */
37
38 #include <string.h>
39 #include <stdlib.h>
40 #include <ctype.h>
41
42 #include "misc.h"
43 #include "gsm-common.h"
44 #include "phones/generic.h"
45 #include "links/cbus.h"
46
47 /* Mobile phone information */
48
49 static GSM_Link link;
50 static GSM_IncomingFunctionType D2711_IncomingFunctions[];
51  
52 #define INFO \
53 { \
54         "dancall|2711|2713", /* Supported models */ \
55                 7,                     /* Max RF Level */ \
56                 0,                     /* Min RF Level */ \
57                 GRF_Percentage,        /* RF level units */ \
58                 7,                     /* Max Battery Level */ \
59                 0,                     /* Min Battery Level */ \
60                 GBU_Percentage,        /* Battery level units */ \
61                 0,                        /* Have date/time support */ \
62                 0,                       /* Alarm supports time only */ \
63                 1,                     /* Alarms available - FIXME */ \
64                 60, 96,                /* Startup logo size - 7110 is fixed at init*/ \
65                 21, 78,                /* Op logo size */ \
66                 14, 72                 /* Caller logo size */ \
67                 }
68
69 GSM_Information D2711_Information = INFO;
70
71
72 static GSM_Phone phone = {
73         D2711_IncomingFunctions,
74         PGEN_IncomingDefault,
75         INFO
76 };
77
78 /* LinkOK is always true for now... */
79 bool D2711_LinkOK = true;
80 char reply_buf[10240];
81
82 static void Terminate()
83 {  
84         return;
85 };
86
87 /* ----------------------------------------------------------------------------------- */
88
89 static GSM_Error Reply(int messagetype, unsigned char *buffer, int length, GSM_Data *data)
90 {
91         printf("[ack]");
92         return GE_NONE;
93 }
94
95 extern int seen_okay;
96 extern char reply_buf[];
97
98 static char *Request(char *c)
99 {
100         link.SendMessage(strlen(c), 0, c);
101         while(!seen_okay)
102                 link.Loop(NULL);
103         return reply_buf;
104 }
105
106 /* ----------------------------------- SMS stuff ------------------------------------- */
107
108
109 GSM_Error ATGSM_GetSMSMessage(GSM_SMSMessage * m)
110 {
111         GSM_Error test = GE_NONE;
112         char writecmd[128];
113         char *s, *t;
114
115         // Set memory
116         m->MemoryType = GMT_SM;     // Type of memory message is stored in.
117         // Send get request
118         sprintf(writecmd, "AT+CMGR=%d\r", m->Location);
119         s = Request(writecmd);
120         if (!s)
121                 return GE_BUSY;
122         t = strchr(s, '\n')+1;
123         if (!strncmp(s, "+CMS ERROR: 321", 15))
124                 return GE_EMPTYSMSLOCATION;
125         if (!strncmp(s, "+CMS ERROR: ", 11))
126                 return GE_INTERNALERROR;
127                 
128         printf("Got %s [%s] as reply for cmgr\n", s, t);
129         {
130                 m->Time.Year=0;
131                 m->Time.Month=0;
132                 m->Time.Day=0;
133                 m->Time.Hour=0;
134                 m->Time.Minute=0;
135                 m->Time.Second=0;
136                 m->Time.Timezone=0;
137         }
138         memset(m->MessageText, 0, 161);
139         strncpy(m->MessageText, (void *) t, 161);
140         m->Length = strlen(t);
141         strcpy(m->MessageCenter.Number, "(unknown)");
142         strcpy(m->MessageCenter.Name, "(unknown)");
143         m->MessageCenter.No = 0;
144         strcpy(m->Sender, "(sender unknown)");
145         m->UDHType = GSM_NoUDH;
146
147         return test;
148 }
149
150
151 GSM_Error ATGSM_DeleteSMSMessage(GSM_SMSMessage * message)
152 {
153         char writecmd[128];
154
155         sprintf(writecmd, "AT+CMGD=%d\r", message->Location);
156
157         Request(writecmd);
158         return GE_NONE;
159 }
160
161
162 GSM_Error ATGSM_SendSMSMessage(GSM_SMSMessage * SMS, int size)
163 {
164         return (GE_NOTIMPLEMENTED);
165 }
166
167 /* ----------------------------------------------------------------------------------- */
168
169 static GSM_Error Initialise(char *port_device, char *initlength,
170                            GSM_ConnectionType connection,
171                            void (*rlp_callback)(RLP_F96Frame *frame))
172 {
173         /* char model[10]; */
174
175         strncpy(link.PortDevice, port_device, 20);
176         link.InitLength = atoi(initlength);
177         link.ConnectionType = connection;
178
179         fprintf(stderr, "Initializing dancall...\n");
180         switch (connection) {
181         case GCT_Serial:
182                 CBUS_Initialise(&link, &phone);
183                 break;
184         default:
185                 return GE_NOTSUPPORTED;
186                 break;
187         }
188         sendat("AT+CPMS=\"SM\",\"SM\"\r");
189         printf("Waiting spurious...\n");
190         if (strncmp(reply_buf, "+CPMS", 5)) {
191                 while (strncmp(reply_buf, "+CPMS", 5))
192                         link.Loop(NULL);
193                 seen_okay = 0;
194                 printf("Waiting OKAY\n");
195                 while (!seen_okay)
196                         link.Loop(NULL);
197                 printf("Link UP\n");
198         }
199
200         return GE_NONE;
201 }
202
203 static GSM_Error
204 GetSMSStatus(GSM_SMSStatus *Status)
205 {
206         int i,j,k,l;
207         char *message = Request("AT+CPMS=\"SM\",\"SM\"\r");
208         if (sscanf(message, "+CPMS: \"SM\",%d,%d,\"SM\",%d,%d", &i, &j, &k, &l)!=4)
209                 return GE_BUSY;
210         Status->UnRead = i;
211         Status->Number = k;
212         return GE_NONE;
213 }
214
215 /* Here we initialise model specific functions called by 'gnokii'. */
216 /* This too needs fixing .. perhaps pass the link a 'request' of certain */
217 /* type and the link then searches the phone functions.... */
218
219 GSM_Functions D2711_Functions = {
220         Initialise,
221         Terminate,
222         UNIMPLEMENTED, /* GetMemoryLocation */
223         UNIMPLEMENTED, /* WritePhonebookLocation */
224         UNIMPLEMENTED, /* GetSpeedDial */
225         UNIMPLEMENTED, /* SetSpeedDial */
226         UNIMPLEMENTED, /* GetMemoryStatus */
227         GetSMSStatus, /* GetSMSStatus */
228         UNIMPLEMENTED, /* GetSMSCentre */
229         UNIMPLEMENTED, /* SetSMSCentre */
230         ATGSM_GetSMSMessage, /* GetSMSMessage */
231         ATGSM_DeleteSMSMessage, /* DeleteSMSMessage */
232         ATGSM_SendSMSMessage, /* SendSMSMessage */
233         UNIMPLEMENTED, /* SaveSMSMessage */
234         UNIMPLEMENTED, /* GetRFLevel */
235         UNIMPLEMENTED, /* GetBatteryLevel */
236         UNIMPLEMENTED, /* GetPowerSource */
237         UNIMPLEMENTED, /* GetDisplayStatus */
238         UNIMPLEMENTED, /* EnterSecurityCode */
239         UNIMPLEMENTED, /* GetSecurityCodeStatus */
240         UNIMPLEMENTED,        /* GetIMEI */
241         UNIMPLEMENTED,    /* GetRevision */
242         UNIMPLEMENTED,       /* GetModel */
243         UNIMPLEMENTED, /* GetManufacturer */
244         UNIMPLEMENTED, /* GetDateTime */
245         UNIMPLEMENTED, /* SetDateTime */
246         UNIMPLEMENTED, /* GetAlarm */
247         UNIMPLEMENTED, /* SetAlarm */
248         UNIMPLEMENTED, /* DialVoice */
249         UNIMPLEMENTED, /* DialData */
250         UNIMPLEMENTED, /* GetIncomingCallNr */
251         UNIMPLEMENTED, /* GetNetworkInfo */
252         UNIMPLEMENTED, /* GetCalendarNote */
253         UNIMPLEMENTED, /* WriteCalendarNote */
254         UNIMPLEMENTED, /* DeleteCalendarNote */
255         UNIMPLEMENTED, /* NetMonitor */
256         UNIMPLEMENTED, /* SendDTMF */
257         UNIMPLEMENTED, /* GetBitmap */
258         UNIMPLEMENTED, /* SetBitmap */
259         UNIMPLEMENTED, /* SetRingtone */
260         UNIMPLEMENTED, /* Reset */ 
261         UNIMPLEMENTED, /* GetProfile */
262         UNIMPLEMENTED, /* SetProfile */
263         UNIMPLEMENTED, /* SendRLPFrame */
264         UNIMPLEMENTED, /* CancelCall */
265         UNIMPLEMENTED, /* EnableDisplayOutput */
266         UNIMPLEMENTED, /* DisableDisplayOutput */
267         UNIMPLEMENTED, /* EnableCellBroadcast */
268         UNIMPLEMENTED, /* DisableCellBroadcast */
269         UNIMPLEMENTED  /* ReadCellBroadcast */
270 };
271
272 static GSM_IncomingFunctionType D2711_IncomingFunctions[] = {
273         { 0, Reply },
274         { 0, Reply },
275         { 0, Reply },
276         { 0, Reply },
277         { 0, Reply },
278         { 0, Reply },
279         { 0, Reply },
280         { 0, Reply },
281         { 0, Reply },
282         { 0, NULL }
283 };