Update: orig2001_12_04_22_45 -> orig2001_12_14_20_46
[gnokii.git] / common / phones / ateric.c
1 /*
2
3   $Id$
4
5   G N O K I I
6
7   A Linux/Unix toolset and driver for mobile phones.
8
9   Copyright 2001 Manfred Jonsson <manfred.jonsson@gmx.de>
10
11   Released under the terms of the GNU GPL, see file COPYING for more details.
12
13   This file provides functions specific to at commands on ericsson
14   phones. See README for more details on supported mobile phones.
15
16   $Log$
17   Revision 1.1.1.1  2001/11/25 21:59:14  short
18   :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
19
20   Revision 1.1  2001/11/19 13:03:18  pkot
21   nk3110.c cleanup
22
23 */
24
25 #include <string.h>
26 #include <stdlib.h>
27 #include <ctype.h>
28
29 #include "misc.h"
30 #include "gsm-common.h"
31 #include "gsm-statemachine.h"
32 #include "phones/generic.h"
33 #include "phones/atgen.h"
34 #include "phones/ateric.h"
35 #include "links/atbus.h"
36 #include "links/cbus.h"
37
38
39 static GSM_Error GetMemoryStatus(GSM_Data *data,  GSM_Statemachine *state)
40 {
41         char req[128];
42         GSM_Error ret;
43  
44         ret = AT_SetMemoryType(data->MemoryStatus->MemoryType,  state);
45         if (ret != GE_NONE)
46                 return ret;
47         sprintf(req, "AT+CPBR=?\r\n");
48         if (SM_SendMessage(state, 11, GOP_GetMemoryStatus, req) != GE_NONE)
49                 return GE_NOTREADY;
50         ret = SM_Block(state, data, GOP_GetMemoryStatus);
51         return ret;
52 }
53
54
55 static GSM_Error ReplyMemoryStatus(int messagetype, unsigned char *buffer, int length, GSM_Data *data)
56 {
57         AT_LineBuffer buf;
58         char *pos;
59  
60         buf.line1 = buffer;
61         buf.length= length;
62         splitlines(&buf);
63         if (buf.line1 == NULL)
64                 return GE_INVALIDMEMORYTYPE;
65         if (data->MemoryStatus) {
66                 if (strstr(buf.line2,"+CPBR")) {
67                         pos = strchr(buf.line2, '-');
68                         if (pos) {
69                                 data->MemoryStatus->Used = atoi(++pos);
70                                 data->MemoryStatus->Free = 0;
71                         } else {
72                                 return GE_NOTSUPPORTED;
73                         }
74                 }
75         }
76         return GE_NONE;
77
78
79
80 void AT_InitEricsson(GSM_Statemachine *state, char *foundmodel, char *setupmodel) {
81         AT_InsertRecvFunction(GOP_GetMemoryStatus, ReplyMemoryStatus);
82         AT_InsertSendFunction(GOP_GetMemoryStatus, GetMemoryStatus);
83 }