1 /****************************************************************************** 2 * 3 * Copyright (C) 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 "stack/bt_types.h" 28 // #include "bt_utils.h" 29 30 /***************************************************************************** 31 ** Constants 32 *****************************************************************************/ 33 /*** class of device settings ***/ 34 #define BTA_UTL_SET_COD_MAJOR_MINOR 0x01 35 #define BTA_UTL_SET_COD_SERVICE_CLASS 0x02 /* only set the bits in the input */ 36 #define BTA_UTL_CLR_COD_SERVICE_CLASS 0x04 37 #define BTA_UTL_SET_COD_ALL 0x08 /* take service class as the input (may clear some set bits!!) */ 38 #define BTA_UTL_INIT_COD 0x0a 39 #define BTA_UTL_SET_COD_RESERVED_2 0x10 /* overwrite the two least significant bits reserved_2 */ 40 41 /***************************************************************************** 42 ** Type Definitions 43 *****************************************************************************/ 44 45 /** for utl_set_device_class() **/ 46 typedef struct { 47 UINT8 reserved_2; 48 UINT8 minor; 49 UINT8 major; 50 UINT16 service; 51 } tBTA_UTL_COD; 52 53 54 #ifdef __cplusplus 55 extern "C" 56 { 57 #endif 58 59 /***************************************************************************** 60 ** External Function Declarations 61 *****************************************************************************/ 62 63 /******************************************************************************* 64 ** 65 ** Function utl_str2int 66 ** 67 ** Description This utility function converts a character string to an 68 ** integer. Acceptable values in string are 0-9. If invalid 69 ** string or string value too large, -1 is returned. 70 ** 71 ** 72 ** Returns Integer value or -1 on error. 73 ** 74 *******************************************************************************/ 75 extern INT16 utl_str2int(const char *p_s); 76 77 /******************************************************************************* 78 ** 79 ** Function utl_strucmp 80 ** 81 ** Description This utility function compares two strings in uppercase. 82 ** String p_s must be uppercase. String p_t is converted to 83 ** uppercase if lowercase. If p_s ends first, the substring 84 ** match is counted as a match. 85 ** 86 ** 87 ** Returns 0 if strings match, nonzero otherwise. 88 ** 89 *******************************************************************************/ 90 extern int utl_strucmp(const char *p_s, const char *p_t); 91 92 /******************************************************************************* 93 ** 94 ** Function utl_itoa 95 ** 96 ** Description This utility function converts a UINT16 to a string. The 97 ** string is NULL-terminated. The length of the string is 98 ** returned. 99 ** 100 ** 101 ** Returns Length of string. 102 ** 103 *******************************************************************************/ 104 extern UINT8 utl_itoa(UINT16 i, char *p_s); 105 106 /******************************************************************************* 107 ** 108 ** Function utl_freebuf 109 ** 110 ** Description This function calls osi_free to free the buffer passed 111 ** in, if buffer pointer is not NULL, and also initializes 112 ** buffer pointer to NULL. 113 ** 114 ** 115 ** Returns Nothing. 116 ** 117 *******************************************************************************/ 118 extern void utl_freebuf(void **p); 119 120 /******************************************************************************* 121 ** 122 ** Function utl_set_device_class 123 ** 124 ** Description This function updates the local Device Class. 125 ** 126 ** Parameters: 127 ** p_cod - Pointer to the device class to set to 128 ** 129 ** cmd - the fields of the device class to update. 130 ** BTA_UTL_SET_COD_RESERVED_2 - overwrite the two least significant bits reserved_2 131 ** BTA_UTL_SET_COD_MAJOR_MINOR, - overwrite major, minor class 132 ** BTA_UTL_SET_COD_SERVICE_CLASS - set the bits in the input 133 ** BTA_UTL_CLR_COD_SERVICE_CLASS - clear the bits in the input 134 ** BTA_UTL_SET_COD_ALL - overwrite major, minor, set the bits in service class, reserved_2 remain unchanged 135 ** BTA_UTL_INIT_COD - overwrite major, minor, and service class, reserved_2 remain unchanged 136 ** 137 ** Returns TRUE if successful, Otherwise FALSE 138 ** 139 *******************************************************************************/ 140 extern BOOLEAN utl_set_device_class(tBTA_UTL_COD *p_cod, UINT8 cmd); 141 142 /******************************************************************************* 143 ** 144 ** Function utl_get_device_class 145 ** 146 ** Description This function get the local Device Class. 147 ** 148 ** Parameters: 149 ** p_cod - Pointer to the device class to get to 150 ** 151 ** 152 ** Returns TRUE if successful, Otherwise FALSE 153 ** 154 *******************************************************************************/ 155 extern BOOLEAN utl_get_device_class(tBTA_UTL_COD *p_cod); 156 157 /******************************************************************************* 158 ** 159 ** Function utl_isintstr 160 ** 161 ** Description This utility function checks if the given string is an 162 ** integer string or not 163 ** 164 ** 165 ** Returns TRUE if successful, Otherwise FALSE 166 ** 167 *******************************************************************************/ 168 extern BOOLEAN utl_isintstr(const char *p_s); 169 170 /******************************************************************************* 171 ** 172 ** Function utl_isdialstr 173 ** 174 ** Description This utility function checks if the given string contains 175 ** only dial digits or not 176 ** 177 ** 178 ** Returns TRUE if successful, Otherwise FALSE 179 ** 180 *******************************************************************************/ 181 extern BOOLEAN utl_isdialstr(const char *p_s); 182 183 #ifdef __cplusplus 184 } 185 #endif 186 187 #endif /* UTL_H */ 188