-/* //device/system/reference-ril/at_tok.h\r
-**\r
-** Copyright 2006, The Android Open Source Project\r
-**\r
-** Licensed under the Apache License, Version 2.0 (the "License");\r
-** you may not use this file except in compliance with the License.\r
-** You may obtain a copy of the License at\r
-**\r
-** http://www.apache.org/licenses/LICENSE-2.0\r
-**\r
-** Unless required by applicable law or agreed to in writing, software\r
-** distributed under the License is distributed on an "AS IS" BASIS,\r
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-** See the License for the specific language governing permissions and\r
-** limitations under the License.\r
-*/\r
-\r
-#ifndef AT_TOK_H\r
-#define AT_TOK_H 1\r
-\r
-int at_tok_start(char **p_cur);\r
-int at_tok_nextint(char **p_cur, int *p_out);\r
-int at_tok_nexthexint(char **p_cur, int *p_out);\r
-\r
-int at_tok_nextbool(char **p_cur, char *p_out);\r
-int at_tok_nextstr(char **p_cur, char **out);\r
-\r
-int at_tok_hasmore(char **p_cur);\r
-void at_tok_skip_bracket(char **p_cur);\r
-\r
-#endif /*AT_TOK_H */\r
+/* //device/system/reference-ril/at_tok.h
+**
+** Copyright 2006, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#ifndef AT_TOK_H
+#define AT_TOK_H 1
+
+int at_tok_start(char **p_cur);
+int at_tok_nextint(char **p_cur, int *p_out);
+int at_tok_nexthexint(char **p_cur, int *p_out);
+
+int at_tok_nextbool(char **p_cur, char *p_out);
+int at_tok_nextstr(char **p_cur, char **out);
+
+int at_tok_hasmore(char **p_cur);
+void at_tok_skip_bracket(char **p_cur);
+
+#endif /*AT_TOK_H */
-#ifndef __ATCHANNEL_H__\r
-#define __ATCHANNEL_H__\r
-\r
-/* //device/system/reference-ril/atchannel.c\r
-**\r
-** Copyright 2006, The Android Open Source Project\r
-**\r
-** Licensed under the Apache License, Version 2.0 (the "License");\r
-** you may not use this file except in compliance with the License.\r
-** You may obtain a copy of the License at\r
-**\r
-** http://www.apache.org/licenses/LICENSE-2.0\r
-**\r
-** Unless required by applicable law or agreed to in writing, software\r
-** distributed under the License is distributed on an "AS IS" BASIS,\r
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-** See the License for the specific language governing permissions and\r
-** limitations under the License.\r
-*/\r
-//code from atchannel.c - android\r
-#include "type/common.h"\r
-\r
-#define AT_ERROR_GENERIC -1\r
-#define AT_ERROR_COMMAND_PENDING -2\r
-#define AT_ERROR_CHANNEL_CLOSED -3\r
-#define AT_ERROR_TIMEOUT -4\r
-#define AT_ERROR_INVALID_THREAD -5 /* AT commands may not be issued from\r
- reader thread (or unsolicited response\r
- callback */\r
-#define AT_ERROR_INVALID_RESPONSE -6 /* eg an at_send_command_singleline that\r
- did not get back an intermediate\r
- response */\r
-\r
-#define MAX_AT_RESPONSE (8 * 1024)\r
-#define MAX_AT_RESP_PREFIX 10\r
-\r
-#define NUM_ELEMS(x) (sizeof(x)/sizeof(x[0]))\r
-\r
-#define ID_RESERVED_AT 0x0229\r
-\r
-\r
-enum ATCommandType{\r
- NO_RESULT, /* no intermediate response expected */\r
- NUMERIC, /* a single intermediate response starting with a 0-9 */\r
- SINGLELINE, /* a single intermediate response starting with a prefix */\r
- MULTILINE /* multiple line intermediate response\r
- starting with a prefix */\r
-};\r
-\r
-enum ATCMEError{\r
- AT_ERROR_MOBILE_FAILRURE =0,\r
- AT_ERROR_NOT_CONNECTED_TO_PHONE =1,\r
- AT_ERROR_LINK_RESERVED =2,\r
- AT_ERROR_OPER_NOT_ALLOWED =3,\r
- AT_ERROR_OPER_NOT_SUPPORTED =4,\r
- AT_ERROR_PH_SIM_PIN_REQUIRED =5,\r
- AT_ERROR_PH_FSIM_PIN_REQUIRED =6,\r
- AT_ERROR_PH_FSIM_PUK_REQUIRED =7,\r
-\r
- AT_ERROR_SIM_NOT_INSERTED =10,\r
- AT_ERROR_SIM_PIN_REQUIRED =11,\r
- AT_ERROR_SIM_PUK_REQUIRED =12,\r
- AT_ERROR_SIM_FAILURE =13,\r
- AT_ERROR_SIM_BUSY =14,\r
- AT_ERROR_SIM_WRONG =15,\r
- AT_ERROR_INCORRECT_PWD =16,\r
- AT_ERROR_SIM_PIN2_REQUIRED =17,\r
- AT_ERROR_SIM_PUK2_REQUIRED =18,\r
-\r
- AT_ERROR_MEMORY_FULL =20,\r
- AT_ERROR_INVALID_INDEX =21,\r
- AT_ERROR_NOT_FOUND =22,\r
- AT_ERROR_MEMORY_FAILURE =23,\r
- AT_ERROR_TEXT_TOO_LONG =24,\r
- AT_ERROR_INVALID_CHAR_IN_STR =25,\r
- AT_ERROR_DIAL_TOO_LONG =26,\r
- AT_ERROR_INVALID_CHAR_IN_DIAL =27,\r
-\r
- AT_ERROR_NO_NETWORK_SVC =30,\r
- AT_ERROR_NETWORK_TIMEOUT =31,\r
- AT_ERROR_EMERGENCY_CALL_ONLY =32,\r
-\r
- AT_ERROR_NET_PERSONAL_PIN_REQ =40,\r
- AT_ERROR_NET_PERSONAL_PUN_REQ =41,\r
- AT_ERROR_NET_SUB_PERSONAL_PIN_REQ =42,\r
- AT_ERROR_NET_SUB_PERSONAL_PUK_REQ =43,\r
- AT_ERROR_PROVIDER_PERSONAL_PIN_REQ =44,\r
- AT_ERROR_PROVIDER_PERSONAL_PUK_REQ =45,\r
- AT_ERROR_CORP_PERSONAL_PIN_REQ =46,\r
- AT_ERROR_CORP_PERSONAL_PUK_REQ =47,\r
- AT_ERROR_HIDDEN_KEY_REQUIRED =48,\r
- AT_ERROR_EAP_METHOD_NOT_SUPPORTED =49,\r
- AT_ERROR_INCORRECT_PARAM =50,\r
-\r
- AT_ERROR_UNKNOWN =100\r
-};\r
-\r
-\r
-\r
-/** a singly-lined list of intermediate responses */\r
-struct ATLine {\r
- struct ATLine *p_next;\r
- char *line;\r
-} ;\r
-\r
-/** Free this with at_response_free() */\r
-struct ATResponse{\r
- int success; /* true if final response indicates\r
- success (eg "OK") */\r
- char *finalResponse; /* eg OK, ERROR */\r
- struct ATLine *p_intermediates; /* any intermediate responses */\r
-} ;\r
-\r
-struct ATReqMetaInfo{\r
- enum ATCommandType type;\r
- char responsePrefix[MAX_AT_RESP_PREFIX];\r
-};\r
-\r
-struct smsDeliveryPDU{\r
-char* cmdLine;\r
-char* pdu;\r
-int len;\r
-};\r
-\r
-//utility API for at command response parsing\r
-/**\r
- * Returns a pointer to the end of the next line\r
- * special-cases the "> " SMS prompt\r
- *\r
- * returns NULL if there is no complete line\r
- */\r
-char * findNextEOL(char *cur);\r
-struct ATResponse * at_response_new();\r
-void at_response_free(struct ATResponse *p_response);\r
-int strStartsWith(const char *line, const char *prefix);\r
- /* SMS prompt character...not \r terminated */\r
-int isFinalResponseError(const char *line);\r
-int isFinalResponseSuccess(const char *line);\r
-\r
-int isFinalResponse(const char *line);\r
-void addIntermediate(const char *line);\r
-void ReleaseResponse(void);\r
-void reverseIntermediates(struct ATResponse *p_response);\r
-void printResponse(void);\r
-TReturn convertCMEError(enum ATCMEError error);\r
-\r
-#include <log.h> /* err */\r
-#include <stdio.h> /* __file__, __line__ */\r
-\r
-#define AT_TOK_ERROR(token) AT_TOK_ERROR_INTERNEL(token, __FILE__, __LINE__)\r
-#define AT_TOK_ERROR_INTERNEL(token, file, line) \\r
-{\\r
- ReleaseResponse();\\r
- err("AT_TOK_ERROR %s:%d %s",file,line,token?token:"");\\r
- return;\\r
-}\\r
-\r
-#define AT_NOTI_TOK_ERROR(token) AT_NOTI_TOK_ERROR_INTERNEL(token, __FILE__, __LINE__)\r
-#define AT_NOTI_TOK_ERROR_INTERNEL(token, file, line) \\r
-{\\r
- err("AT_NOTI_TOK_ERROR_INTERNEL %s:%d %s",file,line,token?token:"");\\r
- return TRUE;\\r
-}\\r
-\r
-#endif /* __ATCHANNEL_H__ */\r
-/*EOF*/\r
-\r
+#ifndef __ATCHANNEL_H__
+#define __ATCHANNEL_H__
+
+/* //device/system/reference-ril/atchannel.c
+**
+** Copyright 2006, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+//code from atchannel.c - android
+#include "type/common.h"
+
+#define AT_ERROR_GENERIC -1
+#define AT_ERROR_COMMAND_PENDING -2
+#define AT_ERROR_CHANNEL_CLOSED -3
+#define AT_ERROR_TIMEOUT -4
+#define AT_ERROR_INVALID_THREAD -5 /* AT commands may not be issued from
+ reader thread (or unsolicited response
+ callback */
+#define AT_ERROR_INVALID_RESPONSE -6 /* eg an at_send_command_singleline that
+ did not get back an intermediate
+ response */
+
+#define MAX_AT_RESPONSE (8 * 1024)
+#define MAX_AT_RESP_PREFIX 10
+
+#define NUM_ELEMS(x) (sizeof(x)/sizeof(x[0]))
+
+#define ID_RESERVED_AT 0x0229
+
+
+enum ATCommandType{
+ NO_RESULT, /* no intermediate response expected */
+ NUMERIC, /* a single intermediate response starting with a 0-9 */
+ SINGLELINE, /* a single intermediate response starting with a prefix */
+ MULTILINE /* multiple line intermediate response
+ starting with a prefix */
+};
+
+enum ATCMEError{
+ AT_ERROR_MOBILE_FAILRURE =0,
+ AT_ERROR_NOT_CONNECTED_TO_PHONE =1,
+ AT_ERROR_LINK_RESERVED =2,
+ AT_ERROR_OPER_NOT_ALLOWED =3,
+ AT_ERROR_OPER_NOT_SUPPORTED =4,
+ AT_ERROR_PH_SIM_PIN_REQUIRED =5,
+ AT_ERROR_PH_FSIM_PIN_REQUIRED =6,
+ AT_ERROR_PH_FSIM_PUK_REQUIRED =7,
+
+ AT_ERROR_SIM_NOT_INSERTED =10,
+ AT_ERROR_SIM_PIN_REQUIRED =11,
+ AT_ERROR_SIM_PUK_REQUIRED =12,
+ AT_ERROR_SIM_FAILURE =13,
+ AT_ERROR_SIM_BUSY =14,
+ AT_ERROR_SIM_WRONG =15,
+ AT_ERROR_INCORRECT_PWD =16,
+ AT_ERROR_SIM_PIN2_REQUIRED =17,
+ AT_ERROR_SIM_PUK2_REQUIRED =18,
+
+ AT_ERROR_MEMORY_FULL =20,
+ AT_ERROR_INVALID_INDEX =21,
+ AT_ERROR_NOT_FOUND =22,
+ AT_ERROR_MEMORY_FAILURE =23,
+ AT_ERROR_TEXT_TOO_LONG =24,
+ AT_ERROR_INVALID_CHAR_IN_STR =25,
+ AT_ERROR_DIAL_TOO_LONG =26,
+ AT_ERROR_INVALID_CHAR_IN_DIAL =27,
+
+ AT_ERROR_NO_NETWORK_SVC =30,
+ AT_ERROR_NETWORK_TIMEOUT =31,
+ AT_ERROR_EMERGENCY_CALL_ONLY =32,
+
+ AT_ERROR_NET_PERSONAL_PIN_REQ =40,
+ AT_ERROR_NET_PERSONAL_PUN_REQ =41,
+ AT_ERROR_NET_SUB_PERSONAL_PIN_REQ =42,
+ AT_ERROR_NET_SUB_PERSONAL_PUK_REQ =43,
+ AT_ERROR_PROVIDER_PERSONAL_PIN_REQ =44,
+ AT_ERROR_PROVIDER_PERSONAL_PUK_REQ =45,
+ AT_ERROR_CORP_PERSONAL_PIN_REQ =46,
+ AT_ERROR_CORP_PERSONAL_PUK_REQ =47,
+ AT_ERROR_HIDDEN_KEY_REQUIRED =48,
+ AT_ERROR_EAP_METHOD_NOT_SUPPORTED =49,
+ AT_ERROR_INCORRECT_PARAM =50,
+
+ AT_ERROR_UNKNOWN =100
+};
+
+
+
+/** a singly-lined list of intermediate responses */
+struct ATLine {
+ struct ATLine *p_next;
+ char *line;
+} ;
+
+/** Free this with at_response_free() */
+struct ATResponse{
+ int success; /* true if final response indicates
+ success (eg "OK") */
+ char *finalResponse; /* eg OK, ERROR */
+ struct ATLine *p_intermediates; /* any intermediate responses */
+} ;
+
+struct ATReqMetaInfo{
+ enum ATCommandType type;
+ char responsePrefix[MAX_AT_RESP_PREFIX];
+};
+
+struct smsDeliveryPDU{
+char* cmdLine;
+char* pdu;
+int len;
+};
+
+//utility API for at command response parsing
+/**
+ * Returns a pointer to the end of the next line
+ * special-cases the "> " SMS prompt
+ *
+ * returns NULL if there is no complete line
+ */
+char * findNextEOL(char *cur);
+struct ATResponse * at_response_new();
+void at_response_free(struct ATResponse *p_response);
+int strStartsWith(const char *line, const char *prefix);
+ /* SMS prompt character...not \r terminated */
+int isFinalResponseError(const char *line);
+int isFinalResponseSuccess(const char *line);
+
+int isFinalResponse(const char *line);
+void addIntermediate(const char *line);
+void ReleaseResponse(void);
+void reverseIntermediates(struct ATResponse *p_response);
+void printResponse(void);
+TReturn convertCMEError(enum ATCMEError error);
+
+#include <log.h> /* err */
+#include <stdio.h> /* __file__, __line__ */
+
+#define AT_TOK_ERROR(token) AT_TOK_ERROR_INTERNEL(token, __FILE__, __LINE__)
+#define AT_TOK_ERROR_INTERNEL(token, file, line) \
+{\
+ ReleaseResponse();\
+ err("AT_TOK_ERROR %s:%d %s",file,line,token?token:"");\
+ return;\
+}\
+
+#define AT_NOTI_TOK_ERROR(token) AT_NOTI_TOK_ERROR_INTERNEL(token, __FILE__, __LINE__)
+#define AT_NOTI_TOK_ERROR_INTERNEL(token, file, line) \
+{\
+ err("AT_NOTI_TOK_ERROR_INTERNEL %s:%d %s",file,line,token?token:"");\
+ return TRUE;\
+}\
+
+#endif /* __ATCHANNEL_H__ */
+/*EOF*/
+
-/* //device/system/reference-ril/at_tok.c\r
-**\r
-** Copyright 2006, The Android Open Source Project\r
-**\r
-** Licensed under the Apache License, Version 2.0 (the "License");\r
-** you may not use this file except in compliance with the License.\r
-** You may obtain a copy of the License at\r
-**\r
-** http://www.apache.org/licenses/LICENSE-2.0\r
-**\r
-** Unless required by applicable law or agreed to in writing, software\r
-** distributed under the License is distributed on an "AS IS" BASIS,\r
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-** See the License for the specific language governing permissions and\r
-** limitations under the License.\r
-*/\r
-\r
-#include "at_tok.h"\r
-#include <string.h>\r
-#include <ctype.h>\r
-#include <stdlib.h>\r
-\r
-/**\r
- * Starts tokenizing an AT response string\r
- * returns -1 if this is not a valid response string, 0 on success.\r
- * updates *p_cur with current position\r
- */\r
-int at_tok_start(char **p_cur)\r
-{\r
- if (*p_cur == NULL) {\r
- return -1;\r
- }\r
-\r
- // skip prefix\r
- // consume "^[^:]:"\r
-\r
- *p_cur = strchr(*p_cur, ':');\r
-\r
- if (*p_cur == NULL) {\r
- return -1;\r
- }\r
-\r
- (*p_cur)++;\r
-\r
- return 0;\r
-}\r
-\r
-static void skipWhiteSpace(char **p_cur)\r
-{\r
- if (*p_cur == NULL) return;\r
-\r
- while (**p_cur != '\0' && isspace(**p_cur)) {\r
- (*p_cur)++;\r
- }\r
-}\r
-\r
-static void skipNextComma(char **p_cur)\r
-{\r
- if (*p_cur == NULL) return;\r
-\r
- while (**p_cur != '\0' && **p_cur != ',') {\r
- (*p_cur)++;\r
- }\r
-\r
- if (**p_cur == ',') {\r
- (*p_cur)++;\r
- }\r
-}\r
-\r
-static char * nextTok(char **p_cur)\r
-{\r
- char *ret = NULL;\r
-\r
- skipWhiteSpace(p_cur);\r
-\r
- if (*p_cur == NULL) {\r
- ret = NULL;\r
- } else if (**p_cur == '"') {\r
- (*p_cur)++;\r
- ret = strsep(p_cur, "\"");\r
- skipNextComma(p_cur);\r
- } else {\r
- ret = strsep(p_cur, ",");\r
- }\r
-\r
- return ret;\r
-}\r
-\r
-\r
-/**\r
- * Parses the next integer in the AT response line and places it in *p_out\r
- * returns 0 on success and -1 on fail\r
- * updates *p_cur\r
- * "base" is the same as the base param in strtol\r
- */\r
-\r
-static int at_tok_nextint_base(char **p_cur, int *p_out, int base, int uns)\r
-{\r
- char *ret;\r
-\r
- if (*p_cur == NULL) {\r
- return -1;\r
- }\r
-\r
- ret = nextTok(p_cur);\r
-\r
- if (ret == NULL) {\r
- return -1;\r
- } else {\r
- long l;\r
- char *end;\r
-\r
- if (uns)\r
- l = strtoul(ret, &end, base);\r
- else\r
- l = strtol(ret, &end, base);\r
-\r
- *p_out = (int)l;\r
-\r
- if (end == ret) {\r
- return -1;\r
- }\r
- }\r
-\r
- return 0;\r
-}\r
-\r
-/**\r
- * Parses the next base 10 integer in the AT response line\r
- * and places it in *p_out\r
- * returns 0 on success and -1 on fail\r
- * updates *p_cur\r
- */\r
-int at_tok_nextint(char **p_cur, int *p_out)\r
-{\r
- return at_tok_nextint_base(p_cur, p_out, 10, 0);\r
-}\r
-\r
-/**\r
- * Parses the next base 16 integer in the AT response line\r
- * and places it in *p_out\r
- * returns 0 on success and -1 on fail\r
- * updates *p_cur\r
- */\r
-int at_tok_nexthexint(char **p_cur, int *p_out)\r
-{\r
- return at_tok_nextint_base(p_cur, p_out, 16, 1);\r
-}\r
-\r
-int at_tok_nextbool(char **p_cur, char *p_out)\r
-{\r
- int ret;\r
- int result;\r
-\r
- ret = at_tok_nextint(p_cur, &result);\r
-\r
- if (ret < 0) {\r
- return -1;\r
- }\r
-\r
- // booleans should be 0 or 1\r
- if (!(result == 0 || result == 1)) {\r
- return -1;\r
- }\r
-\r
- if (p_out != NULL) {\r
- *p_out = (char)result;\r
- }\r
-\r
- return ret;\r
-}\r
-\r
-int at_tok_nextstr(char **p_cur, char **p_out)\r
-{\r
- if (*p_cur == NULL) {\r
- return -1;\r
- }\r
-\r
- *p_out = nextTok(p_cur);\r
-\r
- return 0;\r
-}\r
-\r
-/** returns 1 on "has more tokens" and 0 if no */\r
-int at_tok_hasmore(char **p_cur)\r
-{\r
- return ! (*p_cur == NULL || **p_cur == '\0');\r
-}\r
-\r
-void at_tok_skip_bracket(char **p_cur)\r
-{\r
- if (*p_cur == NULL) return;\r
-\r
- while (**p_cur != '\0' && **p_cur == '(') {\r
- (*p_cur)++;\r
- }\r
-}\r
-\r
-\r
+/* //device/system/reference-ril/at_tok.c
+**
+** Copyright 2006, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#include "at_tok.h"
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+
+/**
+ * Starts tokenizing an AT response string
+ * returns -1 if this is not a valid response string, 0 on success.
+ * updates *p_cur with current position
+ */
+int at_tok_start(char **p_cur)
+{
+ if (*p_cur == NULL) {
+ return -1;
+ }
+
+ // skip prefix
+ // consume "^[^:]:"
+
+ *p_cur = strchr(*p_cur, ':');
+
+ if (*p_cur == NULL) {
+ return -1;
+ }
+
+ (*p_cur)++;
+
+ return 0;
+}
+
+static void skipWhiteSpace(char **p_cur)
+{
+ if (*p_cur == NULL) return;
+
+ while (**p_cur != '\0' && isspace(**p_cur)) {
+ (*p_cur)++;
+ }
+}
+
+static void skipNextComma(char **p_cur)
+{
+ if (*p_cur == NULL) return;
+
+ while (**p_cur != '\0' && **p_cur != ',') {
+ (*p_cur)++;
+ }
+
+ if (**p_cur == ',') {
+ (*p_cur)++;
+ }
+}
+
+static char * nextTok(char **p_cur)
+{
+ char *ret = NULL;
+
+ skipWhiteSpace(p_cur);
+
+ if (*p_cur == NULL) {
+ ret = NULL;
+ } else if (**p_cur == '"') {
+ (*p_cur)++;
+ ret = strsep(p_cur, "\"");
+ skipNextComma(p_cur);
+ } else {
+ ret = strsep(p_cur, ",");
+ }
+
+ return ret;
+}
+
+
+/**
+ * Parses the next integer in the AT response line and places it in *p_out
+ * returns 0 on success and -1 on fail
+ * updates *p_cur
+ * "base" is the same as the base param in strtol
+ */
+
+static int at_tok_nextint_base(char **p_cur, int *p_out, int base, int uns)
+{
+ char *ret;
+
+ if (*p_cur == NULL) {
+ return -1;
+ }
+
+ ret = nextTok(p_cur);
+
+ if (ret == NULL) {
+ return -1;
+ } else {
+ long l;
+ char *end;
+
+ if (uns)
+ l = strtoul(ret, &end, base);
+ else
+ l = strtol(ret, &end, base);
+
+ *p_out = (int)l;
+
+ if (end == ret) {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+/**
+ * Parses the next base 10 integer in the AT response line
+ * and places it in *p_out
+ * returns 0 on success and -1 on fail
+ * updates *p_cur
+ */
+int at_tok_nextint(char **p_cur, int *p_out)
+{
+ return at_tok_nextint_base(p_cur, p_out, 10, 0);
+}
+
+/**
+ * Parses the next base 16 integer in the AT response line
+ * and places it in *p_out
+ * returns 0 on success and -1 on fail
+ * updates *p_cur
+ */
+int at_tok_nexthexint(char **p_cur, int *p_out)
+{
+ return at_tok_nextint_base(p_cur, p_out, 16, 1);
+}
+
+int at_tok_nextbool(char **p_cur, char *p_out)
+{
+ int ret;
+ int result;
+
+ ret = at_tok_nextint(p_cur, &result);
+
+ if (ret < 0) {
+ return -1;
+ }
+
+ // booleans should be 0 or 1
+ if (!(result == 0 || result == 1)) {
+ return -1;
+ }
+
+ if (p_out != NULL) {
+ *p_out = (char)result;
+ }
+
+ return ret;
+}
+
+int at_tok_nextstr(char **p_cur, char **p_out)
+{
+ if (*p_cur == NULL) {
+ return -1;
+ }
+
+ *p_out = nextTok(p_cur);
+
+ return 0;
+}
+
+/** returns 1 on "has more tokens" and 0 if no */
+int at_tok_hasmore(char **p_cur)
+{
+ return ! (*p_cur == NULL || **p_cur == '\0');
+}
+
+void at_tok_skip_bracket(char **p_cur)
+{
+ if (*p_cur == NULL) return;
+
+ while (**p_cur != '\0' && **p_cur == '(') {
+ (*p_cur)++;
+ }
+}
+
+
-/* //device/system/reference-ril/atchannel.c\r
-**\r
-** Copyright 2006, The Android Open Source Project\r
-**\r
-** Licensed under the Apache License, Version 2.0 (the "License");\r
-** you may not use this file except in compliance with the License.\r
-** You may obtain a copy of the License at\r
-**\r
-** http://www.apache.org/licenses/LICENSE-2.0\r
-**\r
-** Unless required by applicable law or agreed to in writing, software\r
-** distributed under the License is distributed on an "AS IS" BASIS,\r
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-** See the License for the specific language governing permissions and\r
-** limitations under the License.\r
-*/\r
-\r
-#include "atchannel.h"\r
-#include "at_tok.h"\r
-\r
-#include <stdio.h>\r
-#include <string.h>\r
-#include <pthread.h>\r
-#include <ctype.h>\r
-#include <stdlib.h>\r
-#include <errno.h>\r
-#include <fcntl.h>\r
-#include <sys/time.h>\r
-#include <time.h>\r
-#include <unistd.h>\r
-\r
-extern enum ATCommandType s_type;\r
-extern char *s_responsePrefix;\r
-extern struct ATResponse *sp_response;\r
-\r
-/**\r
- * returns 1 if line is a final response indicating success\r
- * See 27.007 annex B\r
- */\r
-static const char * s_finalResponsesSuccess[] = {\r
- "OK",\r
-};\r
-/**\r
- * returns 1 if line is a final response indicating error\r
- * See 27.007 annex B\r
- */\r
-static const char * s_finalResponsesError[] = {\r
- "ERROR",\r
- "+CMS ERROR:",\r
- "+CME ERROR:",\r
- "NO ANSWER",\r
- "NO DIALTONE",\r
-};\r
-\r
-\r
-struct ATResponse * at_response_new()\r
-{\r
- return (struct ATResponse *) calloc(1, sizeof(struct ATResponse));\r
-}\r
-\r
-void at_response_free(struct ATResponse *p_response)\r
-{\r
- struct ATLine *p_line;\r
-\r
- if (p_response == NULL) return;\r
-\r
- p_line = p_response->p_intermediates;\r
-\r
- while (p_line != NULL) {\r
- struct ATLine *p_toFree;\r
-\r
- p_toFree = p_line;\r
- p_line = p_line->p_next;\r
-\r
- free(p_toFree->line);\r
- free(p_toFree);\r
- }\r
-\r
- free (p_response->finalResponse);\r
- free (p_response);\r
-}\r
-\r
-char * findNextEOL(char *cur)\r
-{\r
- if (cur[0] == '>' && cur[1] == ' ' && cur[2] == '\0') {\r
- /* SMS prompt character...not \r terminated */\r
- return cur+2;\r
- }\r
-\r
- // Find next newline\r
- while (*cur != '\0' && *cur != '\r' && *cur != '\n') cur++;\r
-\r
- return *cur == '\0' ? NULL : cur;\r
-}\r
-\r
-/** returns 1 if line starts with prefix, 0 if it does not */\r
-int strStartsWith(const char *line, const char *prefix)\r
-{\r
- for ( ; *line != '\0' && *prefix != '\0' ; line++, prefix++) {\r
- if (*line != *prefix) {\r
- return 0;\r
- }\r
- }\r
-\r
- return *prefix == '\0';\r
-}\r
-\r
-int isFinalResponseError(const char *line)\r
-{\r
- unsigned int i;\r
-\r
- for (i = 0 ; i < NUM_ELEMS(s_finalResponsesError) ; i++) {\r
- if (strStartsWith(line, s_finalResponsesError[i])) {\r
- return 1;\r
- }\r
- }\r
-\r
- return 0;\r
-}\r
-\r
-int isFinalResponseSuccess(const char *line)\r
-{\r
- unsigned int i;\r
-\r
- for (i = 0 ; i < NUM_ELEMS(s_finalResponsesSuccess) ; i++) {\r
- if (strStartsWith(line, s_finalResponsesSuccess[i])) {\r
- return 1;\r
- }\r
- }\r
-\r
- return 0;\r
-}\r
-\r
-/**\r
- * returns 1 if line is a final response, either error or success\r
- * See 27.007 annex B\r
- */\r
-int isFinalResponse(const char *line)\r
-{\r
- return isFinalResponseSuccess(line) || isFinalResponseError(line);\r
-}\r
-\r
-/** add an intermediate response to sp_response*/\r
-void addIntermediate(const char *line)\r
-{\r
- struct ATLine *p_new;\r
-\r
- printf("addIntermediate line arrived : %s", line);\r
-\r
- p_new = (struct ATLine*) malloc(sizeof(struct ATLine));\r
-\r
- p_new->line = strdup(line);\r
-\r
- /* note: this adds to the head of the list, so the list\r
- will be in reverse order of lines received. the order is flipped\r
- again before passing on to the command issuer */\r
- p_new->p_next = sp_response->p_intermediates;\r
- sp_response->p_intermediates = p_new;\r
-}\r
-\r
-\r
-//** release sp_response & s_responsePrefix\r
-void ReleaseResponse(void)\r
-{\r
- if(sp_response!=NULL)\r
- {\r
- at_response_free(sp_response);\r
- sp_response = NULL;\r
- }\r
-\r
- if(s_responsePrefix!= NULL)\r
- {\r
- free(s_responsePrefix);\r
- s_responsePrefix = NULL;\r
- }\r
-\r
- s_type = NO_RESULT;\r
-}\r
-\r
-void reverseIntermediates(struct ATResponse *p_response)\r
-{\r
- struct ATLine *pcur,*pnext;\r
-\r
- pcur = p_response->p_intermediates;\r
- p_response->p_intermediates = NULL;\r
-\r
- while (pcur != NULL) {\r
- pnext = pcur->p_next;\r
- pcur->p_next = p_response->p_intermediates;\r
- p_response->p_intermediates = pcur;\r
- pcur = pnext;\r
- }\r
-}\r
-\r
-void printResponse(void)\r
-{\r
- struct ATLine *pcur= NULL;\r
- struct ATLine *pnext= NULL;\r
- int count =0;\r
-\r
- printf("sp_response.success : %d\n", sp_response->success);\r
-\r
- if(sp_response->finalResponse ==NULL)\r
- {\r
- printf("sp_response.finalResponse : NULL\n");\r
- }\r
- else\r
- {\r
- printf("sp_response.finalResponse : %s\n",sp_response->finalResponse);\r
- }\r
-\r
-\r
- pcur = sp_response->p_intermediates;\r
- \r
- if(pcur ==NULL)\r
- {\r
- printf("sp_response.p_intermediates : NULL\n");\r
- }\r
-\r
- while(pcur != NULL)\r
- {\r
- printf("sp_response.p_intermediates[%d] : %s\n",count,pcur->line);\r
- pnext = pcur->p_next; \r
- pcur = pnext;\r
- count++;\r
- }\r
-}\r
-\r
-TReturn convertCMEError(enum ATCMEError error)\r
-{\r
- printf("CMEerror : %d", error);\r
-\r
- //mapping will be done later\r
- return TCORE_RETURN_3GPP_ERROR;\r
-\r
-}\r
+/* //device/system/reference-ril/atchannel.c
+**
+** Copyright 2006, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#include "atchannel.h"
+#include "at_tok.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <pthread.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <time.h>
+#include <unistd.h>
+
+extern enum ATCommandType s_type;
+extern char *s_responsePrefix;
+extern struct ATResponse *sp_response;
+
+/**
+ * returns 1 if line is a final response indicating success
+ * See 27.007 annex B
+ */
+static const char * s_finalResponsesSuccess[] = {
+ "OK",
+};
+/**
+ * returns 1 if line is a final response indicating error
+ * See 27.007 annex B
+ */
+static const char * s_finalResponsesError[] = {
+ "ERROR",
+ "+CMS ERROR:",
+ "+CME ERROR:",
+ "NO ANSWER",
+ "NO DIALTONE",
+};
+
+
+struct ATResponse * at_response_new()
+{
+ return (struct ATResponse *) calloc(1, sizeof(struct ATResponse));
+}
+
+void at_response_free(struct ATResponse *p_response)
+{
+ struct ATLine *p_line;
+
+ if (p_response == NULL) return;
+
+ p_line = p_response->p_intermediates;
+
+ while (p_line != NULL) {
+ struct ATLine *p_toFree;
+
+ p_toFree = p_line;
+ p_line = p_line->p_next;
+
+ free(p_toFree->line);
+ free(p_toFree);
+ }
+
+ free (p_response->finalResponse);
+ free (p_response);
+}
+
+char * findNextEOL(char *cur)
+{
+ if (cur[0] == '>' && cur[1] == ' ' && cur[2] == '\0') {
+ /* SMS prompt character...not \r terminated */
+ return cur+2;
+ }
+
+ // Find next newline
+ while (*cur != '\0' && *cur != '\r' && *cur != '\n') cur++;
+
+ return *cur == '\0' ? NULL : cur;
+}
+
+/** returns 1 if line starts with prefix, 0 if it does not */
+int strStartsWith(const char *line, const char *prefix)
+{
+ for ( ; *line != '\0' && *prefix != '\0' ; line++, prefix++) {
+ if (*line != *prefix) {
+ return 0;
+ }
+ }
+
+ return *prefix == '\0';
+}
+
+int isFinalResponseError(const char *line)
+{
+ unsigned int i;
+
+ for (i = 0 ; i < NUM_ELEMS(s_finalResponsesError) ; i++) {
+ if (strStartsWith(line, s_finalResponsesError[i])) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+int isFinalResponseSuccess(const char *line)
+{
+ unsigned int i;
+
+ for (i = 0 ; i < NUM_ELEMS(s_finalResponsesSuccess) ; i++) {
+ if (strStartsWith(line, s_finalResponsesSuccess[i])) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/**
+ * returns 1 if line is a final response, either error or success
+ * See 27.007 annex B
+ */
+int isFinalResponse(const char *line)
+{
+ return isFinalResponseSuccess(line) || isFinalResponseError(line);
+}
+
+/** add an intermediate response to sp_response*/
+void addIntermediate(const char *line)
+{
+ struct ATLine *p_new;
+
+ printf("addIntermediate line arrived : %s", line);
+
+ p_new = (struct ATLine*) malloc(sizeof(struct ATLine));
+
+ p_new->line = strdup(line);
+
+ /* note: this adds to the head of the list, so the list
+ will be in reverse order of lines received. the order is flipped
+ again before passing on to the command issuer */
+ p_new->p_next = sp_response->p_intermediates;
+ sp_response->p_intermediates = p_new;
+}
+
+
+//** release sp_response & s_responsePrefix
+void ReleaseResponse(void)
+{
+ if(sp_response!=NULL)
+ {
+ at_response_free(sp_response);
+ sp_response = NULL;
+ }
+
+ if(s_responsePrefix!= NULL)
+ {
+ free(s_responsePrefix);
+ s_responsePrefix = NULL;
+ }
+
+ s_type = NO_RESULT;
+}
+
+void reverseIntermediates(struct ATResponse *p_response)
+{
+ struct ATLine *pcur,*pnext;
+
+ pcur = p_response->p_intermediates;
+ p_response->p_intermediates = NULL;
+
+ while (pcur != NULL) {
+ pnext = pcur->p_next;
+ pcur->p_next = p_response->p_intermediates;
+ p_response->p_intermediates = pcur;
+ pcur = pnext;
+ }
+}
+
+void printResponse(void)
+{
+ struct ATLine *pcur= NULL;
+ struct ATLine *pnext= NULL;
+ int count =0;
+
+ printf("sp_response.success : %d\n", sp_response->success);
+
+ if(sp_response->finalResponse ==NULL)
+ {
+ printf("sp_response.finalResponse : NULL\n");
+ }
+ else
+ {
+ printf("sp_response.finalResponse : %s\n",sp_response->finalResponse);
+ }
+
+
+ pcur = sp_response->p_intermediates;
+
+ if(pcur ==NULL)
+ {
+ printf("sp_response.p_intermediates : NULL\n");
+ }
+
+ while(pcur != NULL)
+ {
+ printf("sp_response.p_intermediates[%d] : %s\n",count,pcur->line);
+ pnext = pcur->p_next;
+ pcur = pnext;
+ count++;
+ }
+}
+
+TReturn convertCMEError(enum ATCMEError error)
+{
+ printf("CMEerror : %d", error);
+
+ //mapping will be done later
+ return TCORE_RETURN_3GPP_ERROR;
+
+}