Lines Matching refs:at

20 static void next_list(struct at_client *at)  in next_list()  argument
22 if (at->buf[at->pos] == ',') { in next_list()
23 at->pos++; in next_list()
39 static void skip_space(struct at_client *at) in skip_space() argument
41 while (at->buf[at->pos] == ' ') { in skip_space()
42 at->pos++; in skip_space()
46 int at_get_number(struct at_client *at, uint32_t *val) in at_get_number() argument
50 skip_space(at); in at_get_number()
53 isdigit((unsigned char)at->buf[at->pos]) != 0; in at_get_number()
54 at->pos++, i++) { in at_get_number()
55 *val = *val * 10U + at->buf[at->pos] - '0'; in at_get_number()
62 next_list(at); in at_get_number()
92 static int get_cmd_value(struct at_client *at, struct net_buf *buf, in get_cmd_value() argument
96 uint8_t pos = at->pos; in get_cmd_value()
99 while (cmd_len < buf->len && at->pos != at->buf_max_len) { in get_cmd_value()
101 at->buf[at->pos++] = *str; in get_cmd_value()
104 pos = at->pos; in get_cmd_value()
107 at->buf[at->pos] = '\0'; in get_cmd_value()
108 at->pos = 0U; in get_cmd_value()
109 at->cmd_state = cmd_state; in get_cmd_value()
115 if (pos == at->buf_max_len) { in get_cmd_value()
122 static int get_response_string(struct at_client *at, struct net_buf *buf, in get_response_string() argument
126 uint8_t pos = at->pos; in get_response_string()
129 while (cmd_len < buf->len && at->pos != at->buf_max_len) { in get_response_string()
131 at->buf[at->pos++] = *str; in get_response_string()
134 pos = at->pos; in get_response_string()
137 at->buf[at->pos] = '\0'; in get_response_string()
138 at->pos = 0U; in get_response_string()
139 at->state = state; in get_response_string()
145 if (pos == at->buf_max_len) { in get_response_string()
152 static void reset_buffer(struct at_client *at) in reset_buffer() argument
154 (void)memset(at->buf, 0, at->buf_max_len); in reset_buffer()
155 at->pos = 0U; in reset_buffer()
158 static int at_state_start(struct at_client *at, struct net_buf *buf) in at_state_start() argument
166 at->state = AT_STATE_START_CR; in at_state_start()
171 static int at_state_start_cr(struct at_client *at, struct net_buf *buf) in at_state_start_cr() argument
179 at->state = AT_STATE_START_LF; in at_state_start_cr()
184 static int at_state_start_lf(struct at_client *at, struct net_buf *buf) in at_state_start_lf() argument
186 reset_buffer(at); in at_state_start_lf()
188 at->state = AT_STATE_GET_CMD_STRING; in at_state_start_lf()
191 at->state = AT_STATE_GET_RESULT_STRING; in at_state_start_lf()
198 static int at_state_get_cmd_string(struct at_client *at, struct net_buf *buf) in at_state_get_cmd_string() argument
200 return get_response_string(at, buf, ':', AT_STATE_PROCESS_CMD); in at_state_get_cmd_string()
203 static bool is_cmer(struct at_client *at) in is_cmer() argument
205 if (strncmp(at->buf, "CME ERROR", 9) == 0) { in is_cmer()
212 static int at_state_process_cmd(struct at_client *at, struct net_buf *buf) in at_state_process_cmd() argument
214 if (is_cmer(at)) { in at_state_process_cmd()
215 at->state = AT_STATE_PROCESS_AG_NW_ERR; in at_state_process_cmd()
219 if (at->resp) { in at_state_process_cmd()
220 at->resp(at, buf); in at_state_process_cmd()
221 at->resp = NULL; in at_state_process_cmd()
224 at->state = AT_STATE_UNSOLICITED_CMD; in at_state_process_cmd()
228 static int at_state_get_result_string(struct at_client *at, struct net_buf *buf) in at_state_get_result_string() argument
230 return get_response_string(at, buf, '\r', AT_STATE_PROCESS_RESULT); in at_state_get_result_string()
233 static bool is_ring(struct at_client *at) in is_ring() argument
235 if (strncmp(at->buf, "RING", 4) == 0) { in is_ring()
242 static int at_state_process_result(struct at_client *at, struct net_buf *buf) in at_state_process_result() argument
247 if (is_ring(at)) { in at_state_process_result()
248 at->state = AT_STATE_UNSOLICITED_CMD; in at_state_process_result()
252 if (at_parse_result(at->buf, buf, &result) == 0) { in at_state_process_result()
253 if (at->finish) { in at_state_process_result()
258 at->finish(at, result, cme_err); in at_state_process_result()
263 at->cmd_state = AT_CMD_START; in at_state_process_result()
264 at->state = AT_STATE_START; in at_state_process_result()
269 int cme_handle(struct at_client *at) in cme_handle() argument
274 if (!at_get_number(at, &val) && val <= CME_ERROR_NETWORK_NOT_ALLOWED) { in cme_handle()
280 if (at->finish) { in cme_handle()
281 at->finish(at, AT_RESULT_CME_ERROR, cme_err); in cme_handle()
287 static int at_state_process_ag_nw_err(struct at_client *at, struct net_buf *buf) in at_state_process_ag_nw_err() argument
289 at->cmd_state = AT_CMD_GET_VALUE; in at_state_process_ag_nw_err()
290 return at_parse_cmd_input(at, buf, NULL, cme_handle, in at_state_process_ag_nw_err()
294 static int at_state_unsolicited_cmd(struct at_client *at, struct net_buf *buf) in at_state_unsolicited_cmd() argument
296 if (at->unsolicited) { in at_state_unsolicited_cmd()
297 return at->unsolicited(at, buf); in at_state_unsolicited_cmd()
316 int at_parse_input(struct at_client *at, struct net_buf *buf) in at_parse_input() argument
321 if (at->state < AT_STATE_START || at->state >= AT_STATE_END) { in at_parse_input()
324 ret = parser_cb[at->state](at, buf); in at_parse_input()
327 at->cmd_state = AT_CMD_START; in at_parse_input()
328 at->state = AT_STATE_START; in at_parse_input()
336 static int at_cmd_start(struct at_client *at, struct net_buf *buf, in at_cmd_start() argument
340 if (!str_has_prefix(at->buf, prefix)) { in at_cmd_start()
342 at->state = AT_STATE_UNSOLICITED_CMD; in at_cmd_start()
351 at->cmd_state = AT_CMD_PROCESS_VALUE; in at_cmd_start()
353 at->cmd_state = AT_CMD_GET_VALUE; in at_cmd_start()
359 static int at_cmd_get_value(struct at_client *at, struct net_buf *buf, in at_cmd_get_value() argument
364 reset_buffer(at); in at_cmd_get_value()
365 return get_cmd_value(at, buf, '\r', AT_CMD_PROCESS_VALUE); in at_cmd_get_value()
368 static int at_cmd_process_value(struct at_client *at, struct net_buf *buf, in at_cmd_process_value() argument
374 ret = func(at); in at_cmd_process_value()
375 at->cmd_state = AT_CMD_STATE_END_LF; in at_cmd_process_value()
380 static int at_cmd_state_end_lf(struct at_client *at, struct net_buf *buf, in at_cmd_state_end_lf() argument
391 at->cmd_state = AT_CMD_START; in at_cmd_state_end_lf()
392 at->state = AT_STATE_START; in at_cmd_state_end_lf()
404 int at_parse_cmd_input(struct at_client *at, struct net_buf *buf, in at_parse_cmd_input() argument
411 if (at->cmd_state < AT_CMD_START || in at_parse_cmd_input()
412 at->cmd_state >= AT_CMD_STATE_END) { in at_parse_cmd_input()
415 ret = cmd_parser_cb[at->cmd_state](at, buf, prefix, func, type); in at_parse_cmd_input()
420 if (at->state == AT_STATE_START) { in at_parse_cmd_input()
428 int at_has_next_list(struct at_client *at) in at_has_next_list() argument
430 return at->buf[at->pos] != '\0'; in at_has_next_list()
433 int at_open_list(struct at_client *at) in at_open_list() argument
435 skip_space(at); in at_open_list()
438 if (at->buf[at->pos] != '(') { in at_open_list()
441 at->pos++; in at_open_list()
446 int at_close_list(struct at_client *at) in at_close_list() argument
448 skip_space(at); in at_close_list()
450 if (at->buf[at->pos] != ')') { in at_close_list()
453 at->pos++; in at_close_list()
455 next_list(at); in at_close_list()
460 int at_list_get_string(struct at_client *at, char *name, uint8_t len) in at_list_get_string() argument
464 skip_space(at); in at_list_get_string()
466 if (at->buf[at->pos] != '"') { in at_list_get_string()
469 at->pos++; in at_list_get_string()
471 while (at->buf[at->pos] != '\0' && at->buf[at->pos] != '"') { in at_list_get_string()
475 name[i++] = at->buf[at->pos++]; in at_list_get_string()
484 if (at->buf[at->pos] != '"') { in at_list_get_string()
487 at->pos++; in at_list_get_string()
489 skip_space(at); in at_list_get_string()
490 next_list(at); in at_list_get_string()
495 int at_list_get_range(struct at_client *at, uint32_t *min, uint32_t *max) in at_list_get_range() argument
500 ret = at_get_number(at, &low); in at_list_get_range()
505 if (at->buf[at->pos] == '-') { in at_list_get_range()
506 at->pos++; in at_list_get_range()
510 if (isdigit((unsigned char)at->buf[at->pos]) == 0) { in at_list_get_range()
514 ret = at_get_number(at, &high); in at_list_get_range()
522 next_list(at); in at_list_get_range()
527 void at_register_unsolicited(struct at_client *at, at_resp_cb_t unsolicited) in at_register_unsolicited() argument
529 at->unsolicited = unsolicited; in at_register_unsolicited()
532 void at_register(struct at_client *at, at_resp_cb_t resp, at_finish_cb_t finish) in at_register() argument
534 at->resp = resp; in at_register()
535 at->finish = finish; in at_register()
536 at->state = AT_STATE_START; in at_register()