1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef BROADCAST_PROTOCOL_CONSTANT_H 17 #define BROADCAST_PROTOCOL_CONSTANT_H 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #define MAX_ADV_DATA_LEN 31 24 #define LENGTH_LEN 1 25 #define AD_TYPE_LEN 1 26 #define AD_ID_LEN 2 /* Service UUID or Company ID */ 27 28 /* Adv Struct 29 * | length | Data | 30 * | length | AD Type | AD Data | 31 */ 32 33 /* Flag */ 34 #define FLAG_DATA_LEN 2 35 #define FLAG_AD_DATA 0x2 36 #define FLAG_AD_DATA_LEN (FLAG_DATA_LEN - AD_TYPE_LEN) /* 1 */ 37 #define FLAG_ADV_LEN (LENGTH_LEN + FLAG_DATA_LEN) /* 3 */ 38 39 #define POS_FLAG_LEN 0 40 #define POS_FLAG_AD_TYPE (POS_FLAG_LEN + LENGTH_LEN) /* 1 */ 41 #define POS_FLAG_AD_DATA (POS_FLAG_AD_TYPE + AD_TYPE_LEN) /* 2 */ 42 43 /* Service Data */ 44 #define SERVICE_AD_TYPE 0x16 45 #define SERVICE_AD_TYPE_LEN 1 46 #define SERVICE_UUID 0xFDEE 47 48 #define POS_SERVICE_DATA_LEN (POS_FLAG_AD_DATA + FLAG_AD_DATA_LEN) /* 3 */ 49 #define POS_AD_TYPE (POS_SERVICE_DATA_LEN + LENGTH_LEN) /* 4 */ 50 #define POS_AD_UUID (POS_AD_TYPE + AD_TYPE_LEN) /* 5 */ 51 52 /* Manufacture Data */ 53 #define MANU_AD_TYPE 0xFF 54 #define MANU_COMPANY_ID 0x027D 55 56 #define POS_MANU_DATA_LEN 0 57 #define POS_MANU_AD_TYPE (POS_MANU_DATA_LEN + LENGTH_LEN) /* 1 */ 58 #define POS_MANU_COMPANY_ID (POS_MANU_AD_TYPE + AD_TYPE_LEN) /* 2 */ 59 60 /* Adv head */ 61 #define HEAD_LEN (LENGTH_LEN + AD_TYPE_LEN + AD_ID_LEN) /* 4 */ 62 #define ADV_HEAD_LEN (FLAG_ADV_LEN + HEAD_LEN) /* 7 */ 63 64 /* Payload */ 65 #define MAX_ADV_PAYLOAD_LEN ((MAX_ADV_DATA_LEN) - (ADV_HEAD_LEN)) /* 24 */ 66 #define MAX_RSP_PAYLOAD_LEN ((MAX_ADV_DATA_LEN) - HEAD_LEN) /* 27 */ 67 #define MAX_SUM_PAYLOAD_LEN ((MAX_ADV_PAYLOAD_LEN) + MAX_RSP_PAYLOAD_LEN) /* 51 */ 68 69 /* TLV */ 70 #define TL_LEN 1 71 72 /* Mask */ 73 #define BYTE_MASK 0xFF 74 #define MOST_SIGNIFICANT_4BIT_MASK 0xF0 75 #define LEAST_SIGNIFICANT_4BIT_MASK 0x0F 76 77 /* Byte Shift */ 78 #define BYTE_SHIFT_BIT 1 79 #define BYTE_SHIFT_2BIT 2 80 #define BYTE_SHIFT_4BIT 4 81 #define BYTE_SHIFT_7BIT 7 82 #define BYTE_SHIFT_8BIT 8 83 #define BYTE_SHIFT_13BIT 13 84 85 #ifdef __cplusplus 86 } 87 #endif /* __cplusplus */ 88 #endif /* BROADCAST_PROTOCOL_CONSTANT_H */