1 /******************************************************************************
2  *
3  *  Copyright 2003-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  *  Basic utility functions.
22  *
23  ******************************************************************************/
24 #ifndef UTL_H
25 #define UTL_H
26 
27 #include <cstdint>
28 
29 /*****************************************************************************
30  *  Constants
31  ****************************************************************************/
32 /*** class of device settings ***/
33 #define BTA_UTL_SET_COD_MAJOR_MINOR 0x01
34 #define BTA_UTL_SET_COD_SERVICE_CLASS    \
35   0x02 /* only set the bits in the input \
36         */
37 #define BTA_UTL_CLR_COD_SERVICE_CLASS 0x04
38 #define BTA_UTL_SET_COD_ALL 0x08 /* take service class as the input (may clear some set bits!!) */
39 #define BTA_UTL_INIT_COD 0x0a
40 
41 /*****************************************************************************
42  *  Type Definitions
43  ****************************************************************************/
44 
45 /** for utl_set_device_class() **/
46 typedef struct {
47   uint8_t minor;
48   uint8_t major;
49   uint16_t service;
50 } tBTA_UTL_COD;
51 
52 /*****************************************************************************
53  *  External Function Declarations
54  ****************************************************************************/
55 
56 /*******************************************************************************
57  *
58  * Function         utl_str2int
59  *
60  * Description      This utility function converts a character string to an
61  *                  integer.  Acceptable values in string are 0-9.  If invalid
62  *                  string or string value too large, -1 is returned.
63  *
64  *
65  * Returns          Integer value or -1 on error.
66  *
67  ******************************************************************************/
68 int16_t utl_str2int(const char* p_s);
69 
70 /*******************************************************************************
71  *
72  * Function         utl_strucmp
73  *
74  * Description      This utility function compares two strings in uppercase.
75  *                  String p_s must be uppercase.  String p_t is converted to
76  *                  uppercase if lowercase.  If p_s ends first, the substring
77  *                  match is counted as a match.
78  *
79  *
80  * Returns          0 if strings match, nonzero otherwise.
81  *
82  ******************************************************************************/
83 int utl_strucmp(const char* p_s, const char* p_t);
84 
85 /*******************************************************************************
86  *
87  * Function         utl_itoa
88  *
89  * Description      This utility function converts a uint16_t to a string.  The
90  *                  string is NULL-terminated.  The length of the string is
91  *                  returned.
92  *
93  *
94  * Returns          Length of string.
95  *
96  ******************************************************************************/
97 uint8_t utl_itoa(uint16_t i, char* p_s);
98 
99 /*******************************************************************************
100  *
101  * Function         utl_set_device_class
102  *
103  * Description      This function updates the local Device Class.
104  *
105  * Parameters:
106  *                  p_cod   - Pointer to the device class to set to
107  *
108  *                  cmd     - the fields of the device class to update.
109  *                            BTA_UTL_SET_COD_MAJOR_MINOR, - overwrite major,
110  *                                                           minor class
111  *                            BTA_UTL_SET_COD_SERVICE_CLASS - set the bits in
112  *                                                            the input
113  *                            BTA_UTL_CLR_COD_SERVICE_CLASS - clear the bits in
114  *                                                            the input
115  *                            BTA_UTL_SET_COD_ALL - overwrite major, minor, set
116  *                                                  the bits in service class
117  *                            BTA_UTL_INIT_COD - overwrite major, minor, and
118  *                                               service class
119  *
120  * Returns          true if successful, Otherwise false
121  *
122  ******************************************************************************/
123 bool utl_set_device_class(tBTA_UTL_COD* p_cod, uint8_t cmd);
124 
125 /*******************************************************************************
126  *
127  * Function         utl_isintstr
128  *
129  * Description      This utility function checks if the given string is an
130  *                  integer string or not
131  *
132  *
133  * Returns          true if successful, Otherwise false
134  *
135  ******************************************************************************/
136 bool utl_isintstr(const char* p_s);
137 
138 /*******************************************************************************
139  *
140  * Function         utl_isdialchar
141  *
142  * Description      This utility function checks if the given character
143  *                  is an acceptable dial digit
144  *
145  * Returns          true if successful, Otherwise false
146  *
147  ******************************************************************************/
148 bool utl_isdialchar(const char d);
149 
150 /*******************************************************************************
151  *
152  * Function         utl_isdialstr
153  *
154  * Description      This utility function checks if the given string contains
155  *                  only dial digits or not
156  *
157  *
158  * Returns          true if successful, Otherwise false
159  *
160  ******************************************************************************/
161 bool utl_isdialstr(const char* p_s);
162 
163 #endif /* UTL_H */
164