1 /** @file at.h
2  *  @brief Internal APIs for AT command handling.
3  */
4 
5 /*
6  * Copyright (c) 2015-2016 Intel Corporation
7  *
8  * SPDX-License-Identifier: Apache-2.0
9  */
10 
11 enum at_result {
12 	AT_RESULT_OK,
13 	AT_RESULT_ERROR,
14 	AT_RESULT_CME_ERROR
15 };
16 
17 enum at_cme {
18 	CME_ERROR_AG_FAILURE                    = 0,
19 	CME_ERROR_NO_CONNECTION_TO_PHONE        = 1,
20 	CME_ERROR_OPERATION_NOT_ALLOWED         = 3,
21 	CME_ERROR_OPERATION_NOT_SUPPORTED       = 4,
22 	CME_ERROR_PH_SIM_PIN_REQUIRED           = 5,
23 	CME_ERROR_SIM_NOT_INSERTED              = 10,
24 	CME_ERROR_SIM_PIN_REQUIRED              = 11,
25 	CME_ERROR_SIM_PUK_REQUIRED              = 12,
26 	CME_ERROR_SIM_FAILURE                   = 13,
27 	CME_ERROR_SIM_BUSY                      = 14,
28 	CME_ERROR_INCORRECT_PASSWORD            = 16,
29 	CME_ERROR_SIM_PIN2_REQUIRED             = 17,
30 	CME_ERROR_SIM_PUK2_REQUIRED             = 18,
31 	CME_ERROR_MEMORY_FULL                   = 20,
32 	CME_ERROR_INVALID_INDEX                 = 21,
33 	CME_ERROR_MEMORY_FAILURE                = 23,
34 	CME_ERROR_TEXT_STRING_TOO_LONG          = 24,
35 	CME_ERROR_INVALID_CHARS_IN_TEXT_STRING  = 25,
36 	CME_ERROR_DIAL_STRING_TO_LONG           = 26,
37 	CME_ERROR_INVALID_CHARS_IN_DIAL_STRING  = 27,
38 	CME_ERROR_NO_NETWORK_SERVICE            = 30,
39 	CME_ERROR_NETWORK_TIMEOUT               = 31,
40 	CME_ERROR_NETWORK_NOT_ALLOWED           = 32,
41 	CME_ERROR_UNKNOWN                       = 33,
42 };
43 
44 enum at_state {
45 	AT_STATE_START,
46 	AT_STATE_START_CR,
47 	AT_STATE_START_LF,
48 	AT_STATE_GET_CMD_STRING,
49 	AT_STATE_PROCESS_CMD,
50 	AT_STATE_GET_RESULT_STRING,
51 	AT_STATE_PROCESS_RESULT,
52 	AT_STATE_PROCESS_AG_NW_ERR,
53 	AT_STATE_UNSOLICITED_CMD,
54 	AT_STATE_END
55 };
56 
57 enum at_cmd_state {
58 	AT_CMD_START,
59 	AT_CMD_GET_VALUE,
60 	AT_CMD_PROCESS_VALUE,
61 	AT_CMD_STATE_END_LF,
62 	AT_CMD_STATE_END
63 };
64 
65 enum at_cmd_type {
66 	AT_CMD_TYPE_NORMAL,
67 	AT_CMD_TYPE_UNSOLICITED,
68 	AT_CMD_TYPE_OTHER
69 };
70 
71 struct at_client;
72 
73 /* Callback at_resp_cb_t used to parse response value received for the
74  * particular AT command. Eg: +CIND=<value>
75  */
76 typedef int (*at_resp_cb_t)(struct at_client *at, struct net_buf *buf);
77 
78 /* Callback at_finish_cb used to monitor the success or failure of the AT
79  * command received from server.
80  * Argument 'cme_err' is valid only when argument 'result' is equal to
81  * AT_RESULT_CME_ERROR
82  */
83 typedef int (*at_finish_cb_t)(struct at_client *at, enum at_result result,
84 			      enum at_cme cme_err);
85 typedef int (*parse_val_t)(struct at_client *at);
86 typedef int (*handle_parse_input_t)(struct at_client *at, struct net_buf *buf);
87 typedef int (*handle_cmd_input_t)(struct at_client *at, struct net_buf *buf,
88 				  const char *prefix, parse_val_t func,
89 				  enum at_cmd_type type);
90 
91 struct at_client {
92 	char *buf;
93 	u8_t pos;
94 	u8_t buf_max_len;
95 	u8_t state;
96 	u8_t cmd_state;
97 	at_resp_cb_t resp;
98 	at_resp_cb_t unsolicited;
99 	at_finish_cb_t finish;
100 };
101 
102 /* Register the callback functions */
103 void at_register(struct at_client *at, at_resp_cb_t resp,
104 		 at_finish_cb_t finish);
105 void at_register_unsolicited(struct at_client *at, at_resp_cb_t unsolicited);
106 int at_get_number(struct at_client *at, bt_u32_t *val);
107 /* This parsing will only works for non-fragmented net_buf */
108 int at_parse_input(struct at_client *at, struct net_buf *buf);
109 /* This command parsing will only works for non-fragmented net_buf */
110 int at_parse_cmd_input(struct at_client *at, struct net_buf *buf,
111 		       const char *prefix, parse_val_t func,
112 		       enum at_cmd_type type);
113 int at_check_byte(struct net_buf *buf, char check_byte);
114 int at_list_get_range(struct at_client *at, bt_u32_t *min, bt_u32_t *max);
115 int at_list_get_string(struct at_client *at, char *name, u8_t len);
116 int at_close_list(struct at_client *at);
117 int at_open_list(struct at_client *at);
118 int at_has_next_list(struct at_client *at);
119