Jon West | 2a73667 | 2019-03-17 18:20:19 -0400 | [diff] [blame] | 1 | From 8d27edea9774e92b6b441b63f3936b3cdb1aaa88 Mon Sep 17 00:00:00 2001 |
| 2 | From: penn5 <penn5@users.noreply.github.com> |
| 3 | Date: Mon, 4 Mar 2019 22:21:07 +0000 |
| 4 | Subject: [PATCH 2/2] Add props to control supported features and states (#1) |
| 5 | |
| 6 | * Add bitmask for supported fields |
| 7 | Use persist.sys.bt.unsupport.states, defaults to 0, left-aligned. |
| 8 | Huawei suggest to use 000000000000000000000011111 |
| 9 | |
| 10 | * Add bitmask to LOCAL_SUPPORTED_FEATURES |
| 11 | For Huawei, suggest to use 00000001 |
| 12 | --- |
| 13 | hci/src/hci_packet_parser.cc | 55 ++++++++++++++++++++++++++++++++++++ |
| 14 | 1 file changed, 55 insertions(+) |
| 15 | |
| 16 | diff --git a/hci/src/hci_packet_parser.cc b/hci/src/hci_packet_parser.cc |
| 17 | index 3f4e46cb4..9afa0deab 100644 |
| 18 | --- a/hci/src/hci_packet_parser.cc |
| 19 | +++ b/hci/src/hci_packet_parser.cc |
| 20 | @@ -27,6 +27,8 @@ |
| 21 | #include "hcimsgs.h" |
| 22 | #include "osi/include/log.h" |
| 23 | |
| 24 | +#include <cutils/properties.h> |
| 25 | + |
| 26 | static const command_opcode_t NO_OPCODE_CHECKING = 0; |
| 27 | |
| 28 | static const allocator_t* buffer_allocator; |
| 29 | @@ -137,6 +139,33 @@ static void parse_read_local_extended_features_response( |
| 30 | STREAM_TO_ARRAY(feature_pages[*page_number_ptr].as_array, stream, |
| 31 | (int)sizeof(bt_device_features_t)); |
| 32 | |
| 33 | + int ijk; |
| 34 | + for (ijk = 0; ijk < ((int)sizeof(bt_device_features_t)); ijk++) LOG_DEBUG(LOG_TAG, "supported feature 0x%x is 0x%x", ijk, feature_pages[*page_number_ptr].as_array[ijk]); |
| 35 | + |
| 36 | + char unsupport_bitmask_str[PROPERTY_VALUE_MAX]; |
| 37 | + property_get("persist.sys.bt.unsupport.features", unsupport_bitmask_str, "0"); |
| 38 | + |
| 39 | + unsigned int len = strlen(unsupport_bitmask_str); |
| 40 | + uint8_t unsupport_bitmask[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 41 | + unsigned int c; |
| 42 | + |
| 43 | + for (c = 0; c < len; c++) { |
| 44 | + if (unsupport_bitmask_str[c] == '1') { |
| 45 | + unsupport_bitmask[c/8] = ~ ( (1 << c%8) | ~ unsupport_bitmask[c/8] ); // The logic here is hard to represent in C(++), basically we do a bitwise AND for the bit we are on now. But C(++) pads with 0s so we end up 0ing too much. |
| 46 | + } else if (unsupport_bitmask_str[c] != '0') { |
| 47 | + LOG_ERROR(LOG_TAG, "invalid characters in bitmask; skipping %c", unsupport_bitmask_str[c]); |
| 48 | + goto out; |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + |
| 53 | + for (c = 0; c < ((int)sizeof(bt_device_features_t)); c++) |
| 54 | + feature_pages[*page_number_ptr].as_array[c] &= unsupport_bitmask[c]; |
| 55 | + LOG_DEBUG(LOG_TAG, "generated bitmask 0x%x%x%x%x%x%x%x%x from prop persist.sys.bt.unsupport.features", unsupport_bitmask[0], unsupport_bitmask[1], unsupport_bitmask[2], unsupport_bitmask[3], unsupport_bitmask[4], unsupport_bitmask[5], unsupport_bitmask[6], unsupport_bitmask[7]); |
| 56 | +out: |
| 57 | + for (ijk = 0; ijk < ((int)sizeof(bt_device_features_t)); ijk++) LOG_ERROR(LOG_TAG, "supported feature 0x%x is 0x%x", ijk, feature_pages[*page_number_ptr].as_array[ijk]); |
| 58 | + LOG_DEBUG(LOG_TAG, "supported_features array done"); |
| 59 | + |
| 60 | buffer_allocator->free(response); |
| 61 | } |
| 62 | |
| 63 | @@ -170,6 +199,32 @@ static void parse_ble_read_supported_states_response( |
| 64 | CHECK(stream != NULL); |
| 65 | STREAM_TO_ARRAY(supported_states, stream, (int)supported_states_size); |
| 66 | |
| 67 | + int ijk; |
| 68 | + for (ijk = 0; ijk < ((int)supported_states_size); ijk++) LOG_DEBUG(LOG_TAG, "supported state 0x%x is 0x%x", ijk, supported_states[ijk]); |
| 69 | + |
| 70 | + char unsupport_bitmask_str[PROPERTY_VALUE_MAX]; |
| 71 | + property_get("persist.sys.bt.unsupport.states", unsupport_bitmask_str, "0"); |
| 72 | + |
| 73 | + unsigned int len = strlen(unsupport_bitmask_str); |
| 74 | + uint8_t unsupport_bitmask[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 75 | + unsigned int c; |
| 76 | + |
| 77 | + for (c = 0; c < len; c++) { |
| 78 | + if (unsupport_bitmask_str[c] == '1') { |
| 79 | + unsupport_bitmask[c/8] = ~ ( (1 << c%8) | ~ unsupport_bitmask[c/8] ); // The logic here is hard to represent in C(++), basically we do a bitwise AND for the bit we are on now. But C(++) pads with 0s so we end up 0ing too much. |
| 80 | + } else if (unsupport_bitmask_str[c] != '0') { |
| 81 | + LOG_ERROR(LOG_TAG, "invalid characters in bitmask; skipping %c", unsupport_bitmask_str[c]); |
| 82 | + goto out; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + |
| 87 | + for (c = 0; c < supported_states_size; c++) |
| 88 | + supported_states[c] &= unsupport_bitmask[c]; |
| 89 | + LOG_DEBUG(LOG_TAG, "generated bitmask 0x%x%x%x%x%x%x%x%x from prop persist.sys.bt.unsupport.states", unsupport_bitmask[0], unsupport_bitmask[1], unsupport_bitmask[2], unsupport_bitmask[3], unsupport_bitmask[4], unsupport_bitmask[5], unsupport_bitmask[6], unsupport_bitmask[7]); |
| 90 | +out: |
| 91 | + for (ijk = 0; ijk < ((int)supported_states_size); ijk++) LOG_ERROR(LOG_TAG, "supported state 0x%x is 0x%x", ijk, supported_states[ijk]); |
| 92 | + LOG_DEBUG(LOG_TAG, "supported_states array done"); |
| 93 | buffer_allocator->free(response); |
| 94 | } |
| 95 | |
| 96 | -- |
| 97 | 2.17.1 |
| 98 | |