1 /* 2 * Copyright 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #ifdef __cplusplus 20 #include <cstdint> 21 #else 22 #include <stdint.h> 23 #endif // __cplusplus 24 25 #define DEV_CLASS_LEN 3 26 typedef uint8_t DEV_CLASS[DEV_CLASS_LEN]; /* Device class */ 27 28 #ifdef __cplusplus 29 inline constexpr DEV_CLASS kDevClassEmpty = {}; 30 #endif // __cplusplus 31 32 /* 0x00 is used as unclassified for all minor device classes */ 33 #define BTM_COD_MINOR_UNCLASSIFIED 0x00 34 #define BTM_COD_MINOR_WEARABLE_HEADSET 0x04 35 #define BTM_COD_MINOR_CONFM_HANDSFREE 0x08 36 #define BTM_COD_MINOR_CAR_AUDIO 0x20 37 #define BTM_COD_MINOR_SET_TOP_BOX 0x24 38 39 /* minor device class field for Peripheral Major Class */ 40 /* Bits 6-7 independently specify mouse, keyboard, or combo mouse/keyboard */ 41 #define BTM_COD_MINOR_KEYBOARD 0x40 42 #define BTM_COD_MINOR_POINTING 0x80 43 /* Bits 2-5 OR'd with selection from bits 6-7 */ 44 /* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ 45 #define BTM_COD_MINOR_JOYSTICK 0x04 46 #define BTM_COD_MINOR_GAMEPAD 0x08 47 #define BTM_COD_MINOR_REMOTE_CONTROL 0x0C 48 #define BTM_COD_MINOR_DIGITIZING_TABLET 0x14 49 #define BTM_COD_MINOR_CARD_READER 0x18 /* e.g. SIM card reader */ 50 #define BTM_COD_MINOR_DIGITAL_PAN 0x1C 51 52 /* minor device class field for Imaging Major Class */ 53 /* Bits 5-7 independently specify display, camera, scanner, or printer */ 54 #define BTM_COD_MINOR_DISPLAY 0x10 55 /* Bits 2-3 Reserved */ 56 /* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ 57 58 /* minor device class field for Wearable Major Class */ 59 /* Bits 2-7 meaningful */ 60 #define BTM_COD_MINOR_WRIST_WATCH 0x04 61 #define BTM_COD_MINOR_GLASSES 0x14 62 63 /* minor device class field for Health Major Class */ 64 /* Bits 2-7 meaningful */ 65 #define BTM_COD_MINOR_BLOOD_MONITOR 0x04 66 #define BTM_COD_MINOR_THERMOMETER 0x08 67 #define BTM_COD_MINOR_WEIGHING_SCALE 0x0C 68 #define BTM_COD_MINOR_GLUCOSE_METER 0x10 69 #define BTM_COD_MINOR_PULSE_OXIMETER 0x14 70 #define BTM_COD_MINOR_HEART_PULSE_MONITOR 0x18 71 #define BTM_COD_MINOR_STEP_COUNTER 0x20 72 73 /*************************** 74 * major device class field 75 ***************************/ 76 #define BTM_COD_MAJOR_COMPUTER 0x01 77 #define BTM_COD_MAJOR_PHONE 0x02 78 #define BTM_COD_MAJOR_AUDIO 0x04 79 #define BTM_COD_MAJOR_PERIPHERAL 0x05 80 #define BTM_COD_MAJOR_IMAGING 0x06 81 #define BTM_COD_MAJOR_WEARABLE 0x07 82 #define BTM_COD_MAJOR_HEALTH 0x09 83 #define BTM_COD_MAJOR_UNCLASSIFIED 0x1F 84 85 /*************************** 86 * service class fields 87 ***************************/ 88 #define BTM_COD_SERVICE_LMTD_DISCOVER 0x0020 89 #define BTM_COD_SERVICE_LE_AUDIO 0x0040 90 #define BTM_COD_SERVICE_POSITIONING 0x0100 91 #define BTM_COD_SERVICE_NETWORKING 0x0200 92 #define BTM_COD_SERVICE_RENDERING 0x0400 93 #define BTM_COD_SERVICE_CAPTURING 0x0800 94 #define BTM_COD_SERVICE_OBJ_TRANSFER 0x1000 95 #define BTM_COD_SERVICE_AUDIO 0x2000 96 #define BTM_COD_SERVICE_TELEPHONY 0x4000 97 #define BTM_COD_SERVICE_INFORMATION 0x8000 98 99 /* class of device field macros */ 100 #define BTM_COD_MINOR_CLASS(u8, pd) \ 101 { (u8) = (pd)[2] & 0xFC; } 102 #define BTM_COD_MAJOR_CLASS(u8, pd) \ 103 { (u8) = (pd)[1] & 0x1F; } 104 #define BTM_COD_SERVICE_CLASS(u16, pd) \ 105 { \ 106 (u16) = (pd)[0]; \ 107 (u16) <<= 8; \ 108 (u16) += (pd)[1] & 0xE0; \ 109 } 110 111 /* to set the fields (assumes that format type is always 0) */ 112 #define FIELDS_TO_COD(pd, mn, mj, sv) \ 113 { \ 114 (pd)[2] = mn; \ 115 (pd)[1] = (mj) + ((sv)&BTM_COD_SERVICE_CLASS_LO_B); \ 116 (pd)[0] = (sv) >> 8; \ 117 } 118 119 /* the COD masks */ 120 #define BTM_COD_MINOR_CLASS_MASK 0xFC 121 #define BTM_COD_MAJOR_CLASS_MASK 0x1F 122 #define BTM_COD_SERVICE_CLASS_LO_B 0x00E0 123 #define BTM_COD_SERVICE_CLASS_MASK 0xFFE0 124 125 #define DEVCLASS_TO_STREAM(p, a) \ 126 { \ 127 int ijk; \ 128 for (ijk = 0; ijk < DEV_CLASS_LEN; ijk++) \ 129 *(p)++ = (uint8_t)(a)[DEV_CLASS_LEN - 1 - ijk]; \ 130 } 131 132 #define STREAM_TO_DEVCLASS(a, p) \ 133 { \ 134 int ijk; \ 135 uint8_t* _pa = (uint8_t*)(a) + DEV_CLASS_LEN - 1; \ 136 for (ijk = 0; ijk < DEV_CLASS_LEN; ijk++) *_pa-- = *(p)++; \ 137 } 138