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