1
// *************************************************************************
6
// * Purpose: Mobile Equipment/Terminal Adapter and SMS functions
7
// * (ETSI GSM 07.07 and 07.05)
9
// * Author: Peter Hofmann (software@pxh.de)
11
// * Created: 3.5.1999
12
// *************************************************************************
17
#include <gsmlib/gsm_error.h>
18
#include <gsmlib/gsm_event.h>
19
#include <gsmlib/gsm_phonebook.h>
20
#include <gsmlib/gsm_sms_store.h>
21
#include <gsmlib/gsm_util.h>
22
#include <gsmlib/gsm_at.h>
23
#include <gsmlib/gsm_sms.h>
31
// *** phone capability description (you could also call it phone quirks)
35
bool _hasSMSSCAprefix; // SMS have service centre address prefix
36
int _cpmsParamCount; // number of SMS store parameters to
38
bool _omitsColon; // omits trailing ':' in AT responses
39
bool _veryShortCOPSanswer; // Falcom A2-1
40
bool _wrongSMSStatusCode; // Motorola Timeport 260
41
bool _CDSmeansCDSI; // Nokia Cellular Card Phone RPE-1 GSM900
42
Capabilities(); // constructor, set default behaviours
45
// *** auxiliary structs
47
// Static ME information (AT command sequences given in brackets)
50
string _manufacturer; // (+CGMI)
51
string _model; // (+CGMM)
52
string _revision; // (+CGMR)
53
string _serialNumber; // (+CGSN), IMEI
56
// modes for network operation selection
57
enum OPModes {AutomaticOPMode = 0, ManualOPMode = 1,
58
DeregisterOPMode = 2, ManualAutomaticOPMode = 4};
60
// status codes or network operaton selection
61
enum OPStatus {UnknownOPStatus = 0, AvailableOPStatus = 1,
62
CurrentOPStatus = 2, ForbiddenOPStatus = 3};
64
// network operator info
71
int _numericName; // may be NOT_SET
73
OPInfo() : _status(UnknownOPStatus), _numericName(NOT_SET) {}
77
enum FacilityClass {VoiceFacility = 1, DataFacility = 2, FaxFacility = 4};
78
const int ALL_FACILITIES = VoiceFacility | DataFacility | FaxFacility;
80
// struct to hold password info
87
// call forward reasons
88
// AllReasons encompasses 0..3
89
// AllConditionalReasons encompasses 1..3
90
enum ForwardReason {UnconditionalReason = 0, MobileBusyReason = 1,
91
NoReplyReason = 2, NotReachableReason = 3,
92
AllReasons = 4, AllConditionalReasons = 5, NoReason = 6};
95
enum ForwardMode {DisableMode = 0, EnableMode = 1,
96
RegistrationMode = 3, ErasureMode = 4};
101
bool _active; // status in the network
102
FacilityClass _cl; // voice, fax, or data
103
string _number; // telephone number
104
string _subAddr; // subaddress
105
int _time; // time in the range 1..30 (for NoReplyReason)
106
ForwardReason _reason; // reason for the forwarding
110
typedef Ref<SMSStore> SMSStoreRef;
111
typedef vector<SMSStoreRef> SMSStoreVector;
113
// this class allows access to all functions of a ME/TA as described
114
// in sections 5-8 of ETSI GSM 07.07
115
// Note: If the ME is changed (ie. disconnected an another one connected
116
// to the TA), a new ME object must be created
117
// (Mobile equipment = ME, terminal adapter = TA)
118
class MeTa : public RefBase
121
Ref<Port> _port; // port the ME/TA is connected to
122
Ref<GsmAt> _at; // chat object for the port
123
PhonebookVector _phonebookCache; // cache of all used phonebooks
124
SMSStoreVector _smsStoreCache; // cache of all used phonebooks
125
string _lastPhonebookName; // remember last phonebook set on ME/TA
126
string _lastSMSStoreName; // remember last SMS store set on ME/TA
127
Capabilities _capabilities; // ME/TA quirks
128
GsmEvent _defaultEventHandler; // default event handler
129
// see comments in MeTa::init()
130
string _lastCharSet; // remember last character set
132
// init ME/TA to sensible defaults
133
void init() throw(GsmException);
136
// initialize a new MeTa object given the port
137
MeTa(Ref<Port> port) throw(GsmException);
139
// initialize a new MeTa object given the AT handler
140
//MeTa(Ref<GsmAt> at) throw(GsmException);
142
// set the current phonebook in the ME
143
// remember the last phonebook set for optimisation
144
void setPhonebook(string phonebookName) throw(GsmException);
146
// set the current SMS store in the ME
148
// 1 to set store for reading and deleting
149
// 2 to set store for writing and sending (includes type 1)
150
// 3 to preferred store for receiving SMS (includes types 1 and 2)
151
// remember the last SMS store set for optimisation
152
// if needResultCode is set this optimisation is not done
153
string setSMSStore(string smsStore, int storeTypes,
154
bool needResultCode = false)
157
// get capabilities of this ME/TA
158
Capabilities getCapabilities() const {return _capabilities;}
161
Ref<Port> getPort() {return _port;}
163
// return my at handler
164
Ref<GsmAt> getAt() {return _at;}
166
// set event handler for unsolicited result codes
167
GsmEvent *setEventHandler(GsmEvent *newHandler)
168
{return _at->setEventHandler(newHandler);}
171
void waitEvent(GsmTime timeout) throw(GsmException);
173
// *** ETSI GSM 07.07 Section 5: "General Commands"
175
// return ME information
176
MEInfo getMEInfo() throw(GsmException);
178
// return available character sets
179
vector<string> getSupportedCharSets() throw(GsmException);// (+CSCS=?)
181
// return current character set (default: GSM)
182
string getCurrentCharSet() throw(GsmException);// (+CSCS?)
184
// set character set to use
185
void setCharSet(string charSetName) throw(GsmException);// (+CSCS=)
187
// *** ETSI GSM 07.07 Section 6: "Call control commands and methods"
189
// get extended error report
190
string getExtendedErrorReport() throw(GsmException);// (+CEER)
192
// dial a number, CLI presentation as defined in network
193
void dial(string number) throw(GsmException);// (ATD)
196
// *** ETSI GSM 07.07 Section 7: "Network service related commands"
198
// return available network operators
199
// this fills in all fields of OPInfo with the exception of _mode
200
vector<OPInfo> getAvailableOPInfo() throw(GsmException); // (+COPS=?)
202
// return current network operators
203
// this fills in all the fields of OPInfo with the exception of _status
204
OPInfo getCurrentOPInfo() throw(GsmException);
206
// set network operator
207
// caller must fill in ALL names it has read from previous calls
208
// of getCurrentOPInfo() or getAvailableOPInfo()
209
// (because ME/TA might not implement all names)
210
void setCurrentOPInfo(OPModes mode,
211
string longName = "",
212
string shortName = "",
213
int numericName = NOT_SET) throw(GsmException);
215
// get facility lock capabilities (+CLCK)
216
vector<string> getFacilityLockCapabilities() throw(GsmException);
218
// query facility lock status for named facility
219
bool getFacilityLockStatus(string facility, FacilityClass cl)
223
void lockFacility(string facility, FacilityClass cl, string passwd = "")
227
void unlockFacility(string facility, FacilityClass cl, string passwd = "")
230
// return names of facility for which a password can be set
231
// and the maximum length of the respective password
232
vector<PWInfo> getPasswords() throw(GsmException);// (+CPWD=?)
234
// set password for the given facility
235
void setPassword(string facility, string oldPasswd, string newPasswd)
239
// get CLIP (caller line identification presentation) in the network
240
bool getNetworkCLIP() throw(GsmException);// (+CLIP?)
242
// set CLIP presentation on or off
243
// enables GsmEvent::callerLineID
244
void setCLIPPresentation(bool enable) throw(GsmException);// (+CLIP=)
246
// returns if the above is enable
247
bool getCLIPPresentation() throw(GsmException);// (+CLIP?)
249
// set call forwarding
250
void setCallForwarding(ForwardReason reason,
254
FacilityClass cl = (FacilityClass)ALL_FACILITIES,
255
int forwardTime = NOT_SET)
256
throw(GsmException); // (+CCFC=)
258
// get Information of currently set CF in the network
259
// the caller must give the reason to query
260
void getCallForwardInfo(ForwardReason reason,
264
throw(GsmException); // (+CCFC=)
267
// *** ETSI GSM 07.07 Section 8: "Mobile Equipment control
268
// and status commands"
270
// return battery charge status (+CBC):
271
// 0 ME is powered by the battery
272
// 1 ME has a battery connected, but is not powered by it
273
// 2 ME does not have a battery connected
274
// 3 Recognized power fault, calls inhibited
275
int getBatteryChargeStatus() throw(GsmException);
277
// return battery charge (range 0..100) (+CBC)
278
int getBatteryCharge() throw(GsmException);
280
// get signal strength indication (+CSQ):
281
// 0 -113 dBm or less
283
// 2...30 -109... -53 dBm
284
// 31 -51 dBm or greater
285
// 99 not known or not detectable
286
int getSignalStrength() throw(GsmException);
288
// get channel bit error rate (+CSQ):
289
// 0...7 as RXQUAL values in the table in GSM 05.08 [20] subclause 8.2.4
290
// 99 not known or not detectable
291
int getBitErrorRate() throw(GsmException);
293
// get available phone book memory storage strings (+CPBS=?)
294
vector<string> getPhoneBookStrings() throw(GsmException);
296
// get phone book given the phone book memory storage string
297
PhonebookRef getPhonebook(string phonebookString,
298
bool preload = false) throw(GsmException);
301
// *** ETSI GSM 07.05 SMS functions
303
// return service centre address (+CSCA?)
304
string getServiceCentreAddress() throw(GsmException);
306
// set service centre address (+CSCA=)
307
void setServiceCentreAddress(string sca) throw(GsmException);
309
// return names of available message stores (<mem1>, +CPMS=?)
310
vector<string> getSMSStoreNames() throw(GsmException);
312
// return SMS store given the name
313
SMSStoreRef getSMSStore(string storeName) throw(GsmException);
315
// send a single SMS message
316
void sendSMS(SMSMessageRef smsMessage) throw(GsmException);
318
// set SMS service level
319
// if set to 1 send commands return ACK PDU, 0 is the default
320
void setMessageService(int serviceLevel) throw(GsmException);
322
// return SMS service level
323
unsigned int getMessageService() throw(GsmException);
325
// return true if any of the thre message types GsmEvent::SMSMessageType
326
// is routed directly to the TA and not stored in the ME
327
void getSMSRoutingToTA(bool &smsRouted, // (+CNMI?)
329
bool &statusReportsRouted) throw(GsmException);
331
// sets routing of SMS to TA to true for all supported SMSMessageTypes
332
// if onlyReceptionIndication is set to true
333
// only GsmEvent::SMSReceptionIndication is called
334
// this has two reasons: GSM 07.05 section 3.4.1 does not recommend
335
// direct routing of new SMS to the TA
336
// I cannot test direct routing of SMS because it does not work with
338
void setSMSRoutingToTA(bool enableSMS, bool enableCBS,
339
bool enableStatReport,
340
bool onlyReceptionIndication = true)
344
friend class Phonebook;
345
friend class SMSStore;
349
#endif // GSM_ME_TA_H