1 /****************************************************************************** 2 * 3 * Copyright 2004-2012 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 /****************************************************************************** 20 * 21 * Interface file for BTA AG AT command interpreter. 22 * 23 ******************************************************************************/ 24 #ifndef BTA_AG_AT_H 25 #define BTA_AG_AT_H 26 27 #include <stddef.h> 28 29 #include <cstddef> 30 #include <cstdint> 31 32 /***************************************************************************** 33 * Constants 34 ****************************************************************************/ 35 36 /* AT command argument capabilities */ 37 #define BTA_AG_AT_NONE 0x01 /* no argument */ 38 #define BTA_AG_AT_SET 0x02 /* set value */ 39 #define BTA_AG_AT_READ 0x04 /* read value */ 40 #define BTA_AG_AT_TEST 0x08 /* test value range */ 41 #define BTA_AG_AT_FREE 0x10 /* freeform argument */ 42 43 /* AT command argument format */ 44 #define BTA_AG_AT_STR 0 /* string */ 45 #define BTA_AG_AT_INT 1 /* integer */ 46 47 /***************************************************************************** 48 * Data types 49 ****************************************************************************/ 50 51 /* AT command table element */ 52 typedef struct { 53 const char* p_cmd; /* AT command string */ 54 size_t command_id; /* passed to the callback on p_cmd match */ 55 uint8_t arg_type; /* allowable argument type syntax */ 56 uint8_t fmt; /* whether arg is int or string */ 57 uint8_t min; /* minimum value for int arg */ 58 int16_t max; /* maximum value for int arg */ 59 } tBTA_AG_AT_CMD; 60 61 /* callback function executed when command is parsed */ 62 struct tBTA_AG_SCB; 63 typedef void(tBTA_AG_AT_CMD_CBACK)(tBTA_AG_SCB* p_user, uint16_t command_id, uint8_t arg_type, 64 char* p_arg, char* p_end, int16_t int_arg); 65 66 /* callback function executed to send "ERROR" result code */ 67 typedef void(tBTA_AG_AT_ERR_CBACK)(tBTA_AG_SCB* p_user, bool unknown, const char* p_arg); 68 69 /* AT command parsing control block */ 70 typedef struct { 71 const tBTA_AG_AT_CMD* p_at_tbl; /* AT command table */ 72 tBTA_AG_AT_CMD_CBACK* p_cmd_cback; /* command callback */ 73 tBTA_AG_AT_ERR_CBACK* p_err_cback; /* error callback */ 74 void* p_user; /* user-defined data */ 75 char* p_cmd_buf; /* temp parsing buffer */ 76 uint16_t cmd_pos; /* position in temp buffer */ 77 uint16_t cmd_max_len; /* length of temp buffer to allocate */ 78 uint8_t state; /* parsing state */ 79 } tBTA_AG_AT_CB; 80 81 /***************************************************************************** 82 * Function prototypes 83 ****************************************************************************/ 84 85 /***************************************************************************** 86 * 87 * Function bta_ag_at_init 88 * 89 * Description Initialize the AT command parser control block. 90 * 91 * 92 * Returns void 93 * 94 ****************************************************************************/ 95 void bta_ag_at_init(tBTA_AG_AT_CB* p_cb); 96 97 /***************************************************************************** 98 * 99 * Function bta_ag_at_reinit 100 * 101 * Description Re-initialize the AT command parser control block. This 102 * function resets the AT command parser state and frees 103 * any GKI buffer. 104 * 105 * 106 * Returns void 107 * 108 ****************************************************************************/ 109 void bta_ag_at_reinit(tBTA_AG_AT_CB* p_cb); 110 111 /***************************************************************************** 112 * 113 * Function bta_ag_at_parse 114 * 115 * Description Parse AT commands. This function will take the input 116 * character string and parse it for AT commands according to 117 * the AT command table passed in the control block. 118 * 119 * 120 * Returns void 121 * 122 ****************************************************************************/ 123 void bta_ag_at_parse(tBTA_AG_AT_CB* p_cb, char* p_buf, uint16_t len); 124 125 #endif /* BTA_AG_AT_H */ 126