Branch update for mygnokii2002_03_17_19_29nl
[gnokii.git] / common / newmodules / sniff / sniff.c
1 /*
2
3   G N O K I I
4
5   A Linux/Unix toolset and driver for Nokia mobile phones.
6
7   Released under the terms of the GNU GPL, see file COPYING for more details.
8
9   This file provides an API for accessing functions on the sniff and similar
10   phones.
11
12 */
13
14 #include "config.h"
15
16 /* "Turn on" prototypes in n-sniff.h */
17
18 #define __n_sniff_c 
19
20 /* System header files */
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24  
25 #ifndef WIN32
26
27   #include "devices/device.h"
28
29 #endif
30
31 /* Various header file */
32 #ifndef VC6
33   #include "config.h"
34 #endif
35 #include "misc.h"
36 #include "gsm-api.h"
37 #include "gsm-common.h"
38 #include "files/cfgreader.h"
39 #include "newmodules/sniff/sniff.h"
40 #include "newmodules/n6110.h"
41 #include "newmodules/n7110.h"
42 #include "gsm-networks.h"
43
44 /* Global variables used by code in gsm-api.c to expose the functions
45    supported by this model of phone. */
46
47
48 static char *realmodel;       /* Model from .gnokiirc file. */
49 static char *Port;            /* Port from .gnokiirc file */
50 static char *Initlength;      /* Init length from .gnokiirc file */
51 static char *Connection;      /* Connection type from .gnokiirc file */
52 static char *SynchronizeTime; /* If we set date and time from computer to phone (from .gnokiirc file) */
53 static char *BinDir;                  /* Binaries directory from .gnokiirc file - not used here yet */
54 static GSM_ConnectionType connectiontype;
55
56
57
58
59
60
61
62 /* Here we initialise model specific functions. */
63
64 GSM_Functions Nsniff_Functions = {
65   Nsniff_Initialise,
66   Nsniff_DispatchMessage,
67   NULL_Terminate,
68   NULL_KeepAlive,
69   NOTSUPPORTED,
70   NOTSUPPORTED,  
71   NOTSUPPORTED,
72   NOTSUPPORTED,
73   NOTSUPPORTED,
74   NOTSUPPORTED,
75   NOTSUPPORTED,
76   NOTSUPPORTED,
77   NOTSUPPORTED,
78   NOTSUPPORTED,
79   NOTSUPPORTED,
80   NOTSUPPORTED,
81   NOTSUPPORTED,
82   NOTSUPPORTED,
83   NOTSUPPORTED,
84   NOTSUPPORTED,
85   NOTSUPPORTED,
86   NOTSUPPORTED,
87   NOTSUPPORTED,
88   NOTSUPPORTED,
89   NOTSUPPORTED,
90   NOTSUPPORTED,
91   NOTSUPPORTED,
92   NOTSUPPORTED,
93   NOTSUPPORTED,
94   NOTSUPPORTED,
95   NOTSUPPORTED,
96   NOTSUPPORTED,
97   NOTSUPPORTED,
98   NOTSUPPORTED,
99   NOTSUPPORTED,
100   NOTSUPPORTED,
101   NOTSUPPORTED,
102   NOTSUPPORTED,
103   NOTSUPPORTED,
104   NOTSUPPORTED,
105   NOTSUPPORTED,
106   NOTSUPPORTED,
107   NOTSUPPORTED,
108   NOTSUPPORTED,
109   NOTSUPPORTED,
110   NOTSUPPORTED,
111   NOTSUPPORTED,
112   NOTSUPPORTED,
113   NOTSUPPORTED,
114   NOTSUPPORTED,
115   NOTSUPPORTED,
116   NOTSUPPORTED,
117   NOTSUPPORTED,
118   NOTSUPPORTED,
119   NOTSUPPORTED,
120   NOTSUPPORTED,
121   NOTSUPPORTED,
122   NOTSUPPORTED,
123   NOTSUPPORTED,
124   NOTSUPPORTED,
125   NOTSUPPORTED,  NOTSUPPORTED,
126   NOTSUPPORTED,
127   NOTSUPPORTED,
128   NOTSUPPORTED,
129   NOTSUPPORTED,
130   NOTSUPPORTED,
131   NOTSUPPORTED,
132   NOTSUPPORTED,
133   NOTSUPPORTED,
134   NOTSUPPORTED
135 };
136
137
138
139 /* for all these Phones we support sniff */
140
141 GSM_Information Nsniff_Information = {
142   "3210sniff|3310sniff|3330sniff|5110sniff|5130sniff|5190sniff|6110sniff|6130sniff|6150sniff|6190sniff|8210sniff|8850sniff|6210sniff|6250sniff|7110sniff",
143      /* Supported models in FBUS */
144   "3210sniff|3310sniff|3330sniff|5110sniff|5130sniff|5190sniff|6110sniff|6130sniff|6150sniff|6190sniff|8210sniff|8850sniff|6210sniff|6250sniff|7110sniff",
145      /* Supported models in MBUS */
146   "",
147      /* Supported models in FBUS over infrared */
148   "",
149      /* Supported models in FBUS over DLR3 */
150   "",
151   "6210decode|6250decode|7110decode", /* Supported models in FBUS over Irda sockets */
152   "",
153   "",
154   4,                     /* Max RF Level */
155   0,                     /* Min RF Level */
156   GRF_Arbitrary,         /* RF level units */
157   4,                     /* Max Battery Level */
158   0,                     /* Min Battery Level */
159   GBU_Arbitrary,         /* Battery level units */
160   GDT_None,              /* No date/time support */
161   GDT_None,              /* No alarm support */
162   0                      /* Max alarms = 0 */
163 };
164
165 /* Initialise variables and state machine. */
166 GSM_Error Nsniff_Initialise(char *port_device, char *initlength,
167                           GSM_ConnectionType connection,
168                           void (*rlp_callback)(RLP_F96Frame *frame))
169 {
170
171   GSM_PhonebookEntry phonebook;
172   GSM_SpeedDial speed;
173   GSM_SMSMessage sms;
174   GSM_MemoryStatus status;
175   GSM_NetworkInfo netinfo;
176   GSM_SMSStatus smsstatus;
177   GSM_SMSFolders folders;
178   GSM_MessageCenter smsc;
179   int secstatus;
180   GSM_SecurityCode seccode;
181   GSM_DateTime date;
182   GSM_DateTime alarm;
183   GSM_CalendarNote note;
184   char netmon;
185   GSM_Bitmap logo;
186   GSM_Profile profile;
187   GSM_CBMessage cb;
188   GSM_Network netname;
189   GSM_BinRingtone binring;
190   GSM_AllSimlocks siml;    if (Protocol->Initialise(port_device,initlength,connection,rlp_callback)!=GE_NONE)
191   {
192     return GE_NOTSUPPORTED;
193   }
194
195   CurrentLinkOK = true;                           
196
197   CurrentPhonebookEntry=&phonebook;
198   CurrentSpeedDialEntry=&speed;
199   CurrentSMSMessage=&sms;
200   CurrentMemoryStatus=&status;
201   CurrentNetworkInfo=&netinfo;
202   CurrentSMSStatus=&smsstatus;
203   CurrentSMSFolders=&folders;
204   CurrentMessageCenter=&smsc;
205   CurrentSecurityCodeStatus=&secstatus;
206   CurrentSecurityCode=&seccode;
207   CurrentDateTime=&date;
208   CurrentAlarm=&alarm;
209   CurrentCalendarNote=&note;
210   CurrentNetmonitor=&netmon;
211   CurrentGetBitmap=&logo;
212   CurrentProfile=&profile;
213   CurrentCBMessage=&cb;
214   CurrentGetOperatorNameNetwork=&netname;
215   CurrentGetBinRingtone=&binring;
216   CurrentSimLock=&siml;  
217
218   /* Read config file, once again to get real model */
219     if (CFG_ReadConfig(&realmodel, &Port, &Initlength, &Connection, &BinDir, &SynchronizeTime,false) < 0) {
220         exit(-1);
221     }
222
223   connectiontype = GetConnectionTypeFromString(Connection);
224   return (GE_NONE);
225 }
226
227
228 void Nsniff_DispatchMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType)
229 {
230   
231 /* switch to real Model */
232   if (CheckModel (N6110_Information, realmodel, connectiontype)) 
233         N6110_DispatchMessage( MessageLength, MessageBuffer, MessageType);
234
235   if (CheckModel (N7110_Information, realmodel, connectiontype)) 
236         N7110_DispatchMessage( MessageLength, MessageBuffer, MessageType);
237 }