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