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