1 /* 2 3 $Id$ 4 5 G N O K I I 6 7 A Linux/Unix toolset and driver for the mobile phones. 8 9 This file is part of gnokii. 10 11 Gnokii is free software; you can redistribute it and/or modify 12 it under the terms of the GNU General Public License as published by 13 the Free Software Foundation; either version 2 of the License, or 14 (at your option) any later version. 15 16 Gnokii is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with gnokii; if not, write to the Free Software 23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 25 Copyright (C) 2000 Hugh Blemings, Pavel Janik 26 Copyright (C) 2001 Manfred Jonsson <manfred.jonsson@gmx.de> 27 Copyright (C) 2002-2008 Pawel Kot 28 Copyright (C) 2003 Ladis Michl 29 Copyright (C) 2004 Ron Yorston, Hugo Hass 30 31 This file provides functions specific to generic AT command compatible 32 phones. See README for more details on supported mobile phones. 33 34 */ 35 36 #ifndef _gnokii_atgen_h_ 37 #define _gnokii_atgen_h_ 38 39 #include "gnokii-internal.h" 40 #include "map.h" 41 42 typedef enum { 43 GN_OP_AT_GetCharset = GN_OP_Max, 44 GN_OP_AT_SetCharset, 45 GN_OP_AT_SetPDUMode, 46 GN_OP_AT_Prompt, 47 GN_OP_AT_GetMemoryRange, 48 GN_OP_AT_Ring, 49 GN_OP_AT_IncomingSMS, 50 GN_OP_AT_GetSMSMemorySize, 51 GN_OP_AT_PrepareDateTime, 52 GN_OP_AT_Max /* don't append anything after this entry */ 53 } at_operation; 54 55 typedef enum { 56 AT_CHAR_UNKNOWN = 0x00, 57 AT_CHAR_GSM = 0x01, 58 AT_CHAR_CP437 = 0x02, 59 AT_CHAR_HEXGSM = 0x04, 60 AT_CHAR_HEX437 = 0x08, 61 AT_CHAR_UCS2 = 0x10, 62 } at_charset; 63 64 typedef gn_error (*at_recv_function_type)(int type, unsigned char *buffer, int length, gn_data *data, struct gn_statemachine *state); 65 typedef gn_error (*at_send_function_type)(gn_data *data, struct gn_statemachine *state); 66 typedef gn_error (*at_error_function_type)(int type, int code, struct gn_statemachine *state); 67 68 at_recv_function_type at_insert_recv_function(int type, at_recv_function_type func, struct gn_statemachine *state); 69 at_send_function_type at_insert_send_function(int type, at_send_function_type func, struct gn_statemachine *state); 70 at_error_function_type at_insert_manufacturer_error_function(at_error_function_type func, struct gn_statemachine *state); 71 72 typedef struct { 73 at_send_function_type functions[GN_OP_AT_Max]; 74 gn_incoming_function_type incoming_functions[GN_OP_AT_Max]; 75 at_error_function_type manufacturer_error; 76 int if_pos; 77 int no_smsc; 78 79 /* CBPS (phonebook related) */ 80 gn_memory_type memorytype; 81 int memoryoffset; 82 int memorysize; 83 gn_memory_type smsmemorytype; 84 at_charset availcharsets; 85 at_charset defaultcharset; 86 at_charset charset; 87 88 /* CPMS (sms related) */ 89 int smmemorysize; 90 int mememorysize; 91 92 /* CNMI -- sms notifications */ 93 /* 0: buffer in TA; 94 * 1: discard indication and reject new SMs when TE-TA link is 95 * reserved; otherwise forward directly; 96 * 2: buffer new Sms when TE-TA link is reserved and flush them to TE 97 * after reservation; otherwise forward directly to the TE; 98 * 3: forward directly to TE; 99 */ 100 /* Default should be 3. Specific drivers can overwrite. */ 101 int cnmi_mode; 102 103 /* For call notifications via AT+CLIP */ 104 int clip_supported; 105 gn_call_type last_call_type; 106 gn_call_status last_call_status; 107 108 /* For AT+CPAS */ 109 gn_call_status prev_state; 110 111 /* callbacks */ 112 void (*on_cell_broadcast)(gn_cb_message *msg, struct gn_statemachine *state, void *callback_data); 113 void (*call_notification)(gn_call_status call_status, gn_call_info *call_info, struct gn_statemachine *state, void *callback_data); 114 gn_error (*on_sms)(gn_sms *message, struct gn_statemachine *state, void *callback_data); 115 void (*reg_notification)(gn_network_info *info, void *callback_data); 116 117 /* callback local data */ 118 /* to be passed as callback_data to on_cell_broadcast */ 119 void *cb_callback_data; 120 /* to be passed as callback_data to call_notification */ 121 void *call_callback_data; 122 /* to be passed as callback_data to on_sms */ 123 void *sms_callback_data; 124 /* to be passed as callback_data to reg_notification */ 125 void *reg_callback_data; 126 127 char *timezone; 128 129 /* indicates whether phone is in PDU mode */ 130 int pdumode; 131 132 /* cached information for AT+XXXX=? commands */ 133 struct map *cached_capabilities; 134 135 /* 136 * Indicated whether phone supports extended registration status 137 * 0 - not known (we haven't asked yet) 138 * 1 - extended status not supported 139 * 2 - extended status supported 140 */ 141 int extended_reg_status; 142 143 /* 144 * Some phones use encoding setting to encode just names and the other 145 * entities are encoded using ASCII (Nokia). Other phones encode every 146 * output with the given encoding and require the same for the input 147 * (Sony Ericsson). 148 */ 149 int encode_memory_type; 150 int encode_number; 151 152 /* 153 * Some phones reply with +CREG command with LAC information but with 154 * the bytes swapped. Default is the natural order. 155 */ 156 int lac_swapped; 157 158 /* 159 * Some phones support extended phonebook commands: 160 * AT+SPBR/AT+SPBW 161 */ 162 int extended_phonebook; 163 164 /* 165 * This is for weird encoding found in some Samsung phones. 166 */ 167 int ucs2_as_utf8; 168 } at_driver_instance; 169 170 #define AT_DRVINST(s) (*((at_driver_instance **)(&(s)->driver.driver_instance))) 171 172 typedef struct { 173 char *line1; 174 char *line2; 175 char *line3; 176 char *line4; /* When reading SMS there are 4 ouput lines. Maybe create a table here? */ 177 int length; 178 } at_line_buffer; 179 180 gn_error at_memory_type_set(gn_memory_type mt, struct gn_statemachine *state); 181 gn_error at_error_get(unsigned char *buffer, struct gn_statemachine *state); 182 gn_error at_set_charset(gn_data *data, struct gn_statemachine *state, at_charset charset); 183 184 /* There are shared between various AT drivers */ 185 void splitlines(at_line_buffer *buf); 186 char *skipcrlf(unsigned char *str); 187 char *findcrlf(unsigned char *str, int test, int maxlength); 188 char *strip_quotes(char *s); 189 190 void at_decode(int charset, char *dst, char *src, int len, int ucs2_as_utf8); 191 size_t at_encode(at_charset charset, char *dst, size_t dst_len, const char *src, size_t len); 192 193 extern char *memorynames[]; 194 195 #endif 196