1 /******************************************************************************
2  *
3  *  Copyright (C) 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 /*****************************************************************************
28  *  Constants
29  ****************************************************************************/
30 
31 /* AT command argument capabilities */
32 #define BTA_AG_AT_NONE 0x01 /* no argument */
33 #define BTA_AG_AT_SET 0x02  /* set value */
34 #define BTA_AG_AT_READ 0x04 /* read value */
35 #define BTA_AG_AT_TEST 0x08 /* test value range */
36 #define BTA_AG_AT_FREE 0x10 /* freeform argument */
37 
38 /* AT command argument format */
39 #define BTA_AG_AT_STR 0 /* string */
40 #define BTA_AG_AT_INT 1 /* integer */
41 
42 /*****************************************************************************
43  *  Data types
44  ****************************************************************************/
45 
46 /* AT command table element */
47 typedef struct {
48   const char* p_cmd; /* AT command string */
49   size_t command_id; /* passed to the callback on p_cmd match */
50   uint8_t arg_type;  /* allowable argument type syntax */
51   uint8_t fmt;       /* whether arg is int or string */
52   uint8_t min;       /* minimum value for int arg */
53   int16_t max;       /* maximum value for int arg */
54 } tBTA_AG_AT_CMD;
55 
56 /* callback function executed when command is parsed */
57 typedef void(tBTA_AG_AT_CMD_CBACK)(void* p_user, uint16_t command_id,
58                                    uint8_t arg_type, char* p_arg,
59                                    int16_t int_arg);
60 
61 /* callback function executed to send "ERROR" result code */
62 typedef void(tBTA_AG_AT_ERR_CBACK)(void* p_user, bool unknown, char* p_arg);
63 
64 /* AT command parsing control block */
65 typedef struct {
66   tBTA_AG_AT_CMD* p_at_tbl;          /* AT command table */
67   tBTA_AG_AT_CMD_CBACK* p_cmd_cback; /* command callback */
68   tBTA_AG_AT_ERR_CBACK* p_err_cback; /* error callback */
69   void* p_user;                      /* user-defined data */
70   char* p_cmd_buf;                   /* temp parsing buffer */
71   uint16_t cmd_pos;                  /* position in temp buffer */
72   uint16_t cmd_max_len;              /* length of temp buffer to allocate */
73   uint8_t state;                     /* parsing state */
74 } tBTA_AG_AT_CB;
75 
76 /*****************************************************************************
77  *  Function prototypes
78  ****************************************************************************/
79 
80 /*****************************************************************************
81  *
82  * Function         bta_ag_at_init
83  *
84  * Description      Initialize the AT command parser control block.
85  *
86  *
87  * Returns          void
88  *
89  ****************************************************************************/
90 extern void bta_ag_at_init(tBTA_AG_AT_CB* p_cb);
91 
92 /*****************************************************************************
93  *
94  * Function         bta_ag_at_reinit
95  *
96  * Description      Re-initialize the AT command parser control block.  This
97  *                  function resets the AT command parser state and frees
98  *                  any GKI buffer.
99  *
100  *
101  * Returns          void
102  *
103  ****************************************************************************/
104 extern void bta_ag_at_reinit(tBTA_AG_AT_CB* p_cb);
105 
106 /*****************************************************************************
107  *
108  * Function         bta_ag_at_parse
109  *
110  * Description      Parse AT commands.  This function will take the input
111  *                  character string and parse it for AT commands according to
112  *                  the AT command table passed in the control block.
113  *
114  *
115  * Returns          void
116  *
117  ****************************************************************************/
118 extern void bta_ag_at_parse(tBTA_AG_AT_CB* p_cb, char* p_buf, uint16_t len);
119 
120 #endif /* BTA_AG_AT_H */
121