1 /*************************************************************************** 2 * copyright : (C) 2004 by Hendrik Sattler * 3 * mail : post@hendrik-sattler.de * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 * * 10 ***************************************************************************/ 11 12 #ifndef ATCOMMAND_H 13 #define ATCOMMAND_H 14 15 #include "intincl.h" 16 17 #include "stdlib.h" 18 #include <sys/types.h> 19 20 struct at_hw_access { 21 char* (*read) (int (*stop_condition)(const char*, const size_t)); 22 int (*write) (const char* data, size_t count); 23 }; 24 25 /** MUST be run before any other at_* function is used 26 * @param tty must not be NULL, specifies how to access the tty 27 * @param pin may be NULL, PIN to use _once_ in automatic pin handling 28 */ 29 void at_init (struct at_hw_access* tty, char* pin); 30 void at_set_tty(struct at_hw_access* tty); 31 32 /** test if the vendor is supported and model not blacklisted 33 */ 34 int at_sie_supported (); 35 36 /* useful wrapper around tty_read_line() that removes 37 * echos, empty lines and does pin handling 38 * use tty_read_line() if you don't need those things 39 */ 40 char* at_read_line (); 41 42 /* used as callback for tty_read_line() 43 */ 44 int at_check_line_end (const char* input, const size_t len); 45 46 /** may be used directly for simple commands of the form AT<command>[=<parmlist>] 47 * @param command must not be NULL 48 * @param parmlist may be NULL, also see AT_READ_SUFFIX 49 */ 50 void at_command_send (const char* command, const char* parmlist); 51 52 /** may be used by syntax/value requests of the form AT<command>? 53 * @param command must not be NULL 54 */ 55 void at_syntax_request (const char* command); 56 57 /** may be used to send data, e.g. requested by an "> " prompt 58 */ 59 void at_data_send (const char* data, size_t size); 60 61 /** evaluate a return value (a line returned by the phone) 62 * @param reponse the reponse line 63 * @param command may be NULL, needed to detect a command prefix 64 * @param content if a prefix was detected and content is not NULL 65 * *content is a pointer to the first character after 66 * the command prefix in response. If no command prefix 67 * was detectet, *content points to response 68 */ 69 enum return_code { 70 AT_RET_ERROR = 0x01, //also mask for errors 71 AT_RET_ERROR_CME = 0x03, 72 AT_RET_ERROR_CMS = 0x05, 73 AT_RET_OK = 0x00, 74 AT_RET_ANSWER = 0x02, //answer line for a command 75 AT_RET_OTHER = 0x04 //none of the above 76 }; 77 enum return_code at_line_type (const char* response, 78 const char* command, 79 char** content); 80 81 82 /* comfort functions */ 83 84 /* used by commands that expect only two lines in the response 85 * - first line for the data 86 * - second line for command status 87 * This returns the data or NULL on any error. 88 * A possible command prefix is removed from the data. 89 * command may be NULL (avoids prefix removal) 90 */ 91 char* at_get_value (const char* command); 92 93 /** parse an AT string list 94 * @param a string list that looks like '("...","...",.....,"...")' 95 * @return same format as str_split() 96 */ 97 char** at_parse_stringlist (char* stringlist); 98 99 /* some shortcuts with caching 100 */ 101 char* at_get_vendor (void); 102 char* at_get_model (void); 103 104 /* end of comfort functions */ 105 106 107 108 109 /** send a fragment of a binary file to the phone 110 * if part or total is 0 (means deleting) the value of total is ignored 111 * if part or total is negative, part and total are ignored 112 * @param ftype file type, must not be NULL 113 * @param slot must be a valid value for the chosen file type 114 * @param part count, starting at 1, less or equal than total 115 * @param total maximum part number 116 */ 117 char* at_sie_binary_write (const char* ftype, unsigned int slot, 118 int part, int total); 119 120 /** read binary files 121 * @param ftype file type, must not be NULL 122 * @param slot must be a valid value for the chosen file type 123 */ 124 char* at_sie_binary_read (const char* ftype, unsigned int slot); 125 126 /** write a phonebook entry 127 * If number or text are NULL, both are ignored. 128 * @param slot where to write to 129 * @param number number of the entry 130 * @param numtype GSM number type of the entry 131 * @param text text of the entry 132 */ 133 void at_gen_phonebook_write (unsigned int slot, const char* number, 134 unsigned int numtype, const char* text); 135 136 /** read phonebook with a defined range 137 * @param slot_low start of the range 138 * @param slot_high end of the range 139 */ 140 char* at_gen_phonebook_read (unsigned int slot_low, unsigned int slot_high); 141 char* at_sie_phonebook_read_sorted (unsigned int slot_low, unsigned int slot_high); 142 143 /** read address book slots like a phonebook 144 * @param slot address book slot to access 145 * @param type type of numbers: 0-3; ignored if <0 146 */ 147 char* at_sie_phonebook_vcf_read (unsigned int slot, int type); 148 149 /** select the phonebook memory to use for further action 150 * @param mem must not be NULL 151 * @return return the used command or NULL if mem is NULL 152 */ 153 char* at_gen_phonebook_select (const char* mem); 154 char* at_sie_phonebook_select (const char* mem); 155 156 /** delete slot from the previously selected phonebook memory 157 */ 158 void at_gen_sms_delete (unsigned int slot); 159 160 /** send SMS from slot to number 161 * @param number if NULL, it is ignored 162 */ 163 void at_gen_sms_slot_send (unsigned int slot, const char* number); 164 165 /** send a SMS directly (not stored in the phone) 166 * @param len PDU length (use the libsmspdu helper function!) 167 */ 168 void at_gen_sms_send (unsigned int len); 169 170 /** store a SMS in the phone (not sent) 171 * @param len PDU length (use the libsmspdu helper function!) 172 */ 173 void at_gen_sms_store (unsigned int len); 174 175 /** select SMS storages 176 * @param mem1 must not be NULL, 177 * @param mem2 if NULL, mem2 and mem3 are ignored, 178 * @param mem3 if NULL, mem3 is ignored 179 */ 180 void at_gen_sms_mem (const char* mem1, const char* mem2, const char* mem3); 181 182 183 char* at_gen_sms_slot_read (unsigned int slot); 184 char* at_sie_sms_slot_read (unsigned int slot); 185 char* at_gen_sms_list_read (unsigned int list_id); 186 char* at_sie_sms_list_read (unsigned int list_id); 187 188 189 void at_gen_charset (const char* charset); 190 void at_gen_smsc (const char* number); 191 void at_gen_pin (const char* pin); 192 193 char* at_gen_lock (const char* lock, int mode, 194 const char* password, uint8_t class); 195 char* at_sie_lock (const char* lock, int mode, 196 const char* password, uint8_t class); 197 char* at_gen_password (const char* lock, 198 const char* oldpin, 199 const char* newpin); 200 char* at_sie_password (const char* lock, 201 const char* oldpin, 202 const char* newpin); 203 204 /* those functions are for direct SMS receive mode 205 * see Siemens manual for L55, S45 or S35i for details 206 */ 207 void at_gen_sms_phase (int enable); 208 void at_gen_msg_direct (int mode, int mt, int bm, int ds); 209 210 /* Returns NULL if all keys from keylist were processed 211 * else returns a pointer in keylist to the first unprocessed key. 212 * This is normal, just recall it again with the new pointer 213 * (after you read the response to the issued command). 214 */ 215 char* at_gen_keypad (char* keylist, uint8_t duration, uint8_t pause); 216 217 218 219 220 /* common strings 221 */ 222 #define AT_PREFIX "AT" 223 #define AT_GENERIC_PREFIX "+C" 224 #define AT_SIEMENS_PREFIX "^S" 225 #define AT_READ_SUFFIX "?" 226 #define AT_REPLY_SEPERATOR ": " 227 #define AT_WRITE_DELIM "=" 228 229 /* often, commands are prefixed to a reply 230 * or the following status messages appear 231 */ 232 #define AT_OK "OK" 233 #define AT_ERROR "ERROR" 234 #define AT_REPLY_PREFIX(s) s""AT_REPLY_SEPERATOR 235 #define AT_ERROR_CME AT_REPLY_PREFIX("+CME ERROR") 236 #define AT_ERROR_CMS AT_REPLY_PREFIX("+CMS ERROR") 237 238 /* generic commands 239 * those may work for phones from all vendors 240 */ 241 //those have no parameters at all 242 #define AT_GEN_INIT "Z" // init the phone to defaults 243 #define AT_GEN_VENDOR "+CGMI" // get vendor 244 #define AT_GEN_MODEL "+CGMM" // get model 245 #define AT_GEN_REVISION "+CGMR" // get model revision 246 #define AT_GEN_IMSI "+CGSN" // get international mobile subcriber identity ????? 247 #define AT_GEN_IMEI "+CIMI" // get international mobile entity identity 248 #define AT_GEN_BATTERY "+CBC" // get battery status 249 #define AT_GEN_SIGNAL "+CSQ" // get signal strength/ber 250 #define AT_GEN_HANGUP "+CHUP" // terminate a call 251 #define AT_GEN_CALLINFO "+CLCC" // list current calls 252 253 //these ones may use the parameter scheme ?/=?/=<...> 254 #define AT_GEN_ECHO_ENABLE "E1" // enable echo response 255 #define AT_GEN_ECHO_DISABLE "E0" // disable echo response 256 #define AT_GEN_ERROR "+CMEE" // select type of response for errors 257 #define AT_GEN_PB_SELECT "+CPBS" // select phonebook memory / get list of phonebook memories 258 #define AT_GEN_PB_READ "+CPBR" // read entries from phonebook 259 #define AT_GEN_PB_WRITE "+CPBW" // write entries to phonebook 260 #define AT_GEN_SMS_MEM "+CPMS" // select SMS memory / get list 261 #define AT_GEN_SMS_STORE "+CMGW" // store SMS to slot 262 #define AT_GEN_SMS_DELETE "+CMGD" // delete SMS slot 263 #define AT_GEN_SMS_SEND "+CMGS" // send SMS (without storing to a slot) 264 #define AT_GEN_SMS_SLOT_SEND "+CMSS" // send SMS from slot 265 #define AT_GEN_SMS_SLOT_READ "+CMGR" // read SMS from slot (marks unread as read) 266 #define AT_GEN_SMS_LIST_READ "+CMGL" // read SMS by status (marks unread as read) 267 #define AT_GEN_SMS_PHASE "+CSMS" 268 #define AT_GEN_MSG_DIRECT "+CNMI" 269 #define AT_GEN_MSG_ACK "+CNMA" 270 #define AT_GEN_SMSC "+CSCA" // set/get SMSC 271 #define AT_GEN_CHARSET "+CSCS" // set/get current character set 272 #define AT_GEN_PIN "+CPIN" // enter pin (DANGEROUS) 273 #define AT_GEN_TIME "+CCLK" // set/read time 274 #define AT_GEN_OPERATOR "+COPS" // get operator 275 #define AT_GEN_CSD_STATUS "+CREG" // get area code and cell id (for CSD) 276 #define AT_GEN_GPRS_STATUS "+CGREG" // get area code and cell id (for GPRS) 277 #define AT_GEN_GPRS_ATTACH "+CGATT" // is GPRS in attached mode? 278 #define AT_GEN_GPRS_CLASS "+CGCLASS" //get GPRS class 279 #define AT_GEN_LOCK "+CLCK" // set/get lock status 280 #define AT_GEN_PASSWORD "+CPWD" // set/change password to a lock 281 #define AT_GEN_TERM_CMODE "+CMEC" // mobile termination control mode (needed for keypad control) 282 #define AT_GEN_KEYPAD "+CKPD" // keypad control 283 284 /* siemens-specific commands 285 * probably only works with phones made by Siemens 286 * not all of those are (really) fully documented 287 */ 288 #define AT_SIE_PB_VCF_READ "^SDBR" // read address book like phonebook 289 #define AT_SIE_PB_READ_SORTED "^SPBG" // read phonebook pre-sorted 290 #define AT_SIE_PB_SELECT "^SPBS" // select phonebook memory / get list of phonebook memories 291 #define AT_SIE_PB_DELETE "^SDLD" // delete for phonebooks (only DC, MD and LD) 292 #define AT_SIE_CARD_ID "^SCID" // get SIM card identity number 293 #define AT_SIE_BIN_READ "^SBNR" // read binary data 294 #define AT_SIE_BIN_WRITE "^SBNW" // write binary data 295 #define AT_SIE_SMS_SLOT_READ "^SMGR" // read SMS from slot (without marking unread as read) 296 #define AT_SIE_SMS_LIST_READ "^SMGL" // read SMS by list (without marking unread as read) 297 #define AT_SIE_LOCK "^SLCK" // set/get lock status 298 #define AT_SIE_PASSWORD "^SPWD" // set/change password to a lock 299 #define AT_SIE_PREF_OP_READ "^SPLR" // read an entry from the preferred operator list 300 #define AT_SIE_PREF_OP_WRITE "^SPLW" // write an entry to the preferred operator list 301 #define AT_SIE_OP_LIST "^SPLM" // read PLMN list 302 303 /* currentyl not used but available on some phones 304 ^SABD // accessory for bluetooth data 305 ^SACD // accessory data 306 ^SACM // output ACM 307 ^SBLK // clear blacklist 308 ^SBMH // bookmark handling 309 ^SCCM // CC monitor 310 ^SCKA // sim card status 311 ^SCKS // sim card status (unsolicited) 312 ^SCNI // call number information 313 ^SGDV // GPRS data volume 314 ^SICO // icon control 315 ^SIFS // query interface setting 316 ^SKPD // keypad control 317 ^SLNG // language settings 318 ^SMSO // mobile switch off 319 ^SNFS // NF hardware select 320 ^SNFV // volume set 321 ^SPIC // output PIN counter 322 ^SPLM // get PLMN 323 ^SPLR // read preferred operator list 324 ^SPLW // write preferred operator list 325 ^SPST // play signal tone 326 ^SPTT // push to talk 327 ^SRMP // ring melody playback 328 ^SSET // profile setting control 329 ^SSTK // SIM ToolKit 330 ^SVMC // voice memo control 331 */ 332 333 #endif 334