Skip to content

Commit b6b4b2a

Browse files
penn5phhusson
authored andcommitted
Add props to control supported features and states (#1)
* Add bitmask for supported fields Use persist.sys.bt.unsupport.states, defaults to 0, left-aligned. Huawei suggest to use 000000000000000000000011111 * Add bitmask to LOCAL_SUPPORTED_FEATURES For Huawei, suggest to use 00000001
1 parent 4433923 commit b6b4b2a

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

hci/src/hci_packet_parser.cc

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "hcimsgs.h"
2828
#include "osi/include/log.h"
2929

30+
#include <cutils/properties.h>
31+
3032
static const command_opcode_t NO_OPCODE_CHECKING = 0;
3133

3234
static const allocator_t* buffer_allocator;
@@ -123,6 +125,33 @@ static void parse_read_local_extended_features_response(
123125
STREAM_TO_ARRAY(feature_pages[*page_number_ptr].as_array, stream,
124126
(int)sizeof(bt_device_features_t));
125127

128+
int ijk;
129+
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]);
130+
131+
char unsupport_bitmask_str[PROPERTY_VALUE_MAX];
132+
property_get("persist.sys.bt.unsupport.features", unsupport_bitmask_str, "0");
133+
134+
unsigned int len = strlen(unsupport_bitmask_str);
135+
uint8_t unsupport_bitmask[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
136+
unsigned int c;
137+
138+
for (c = 0; c < len; c++) {
139+
if (unsupport_bitmask_str[c] == '1') {
140+
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.
141+
} else if (unsupport_bitmask_str[c] != '0') {
142+
LOG_ERROR(LOG_TAG, "invalid characters in bitmask; skipping %c", unsupport_bitmask_str[c]);
143+
goto out;
144+
}
145+
}
146+
147+
148+
for (c = 0; c < ((int)sizeof(bt_device_features_t)); c++)
149+
feature_pages[*page_number_ptr].as_array[c] &= unsupport_bitmask[c];
150+
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]);
151+
out:
152+
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]);
153+
LOG_DEBUG(LOG_TAG, "supported_features array done");
154+
126155
buffer_allocator->free(response);
127156
}
128157

@@ -156,6 +185,32 @@ static void parse_ble_read_supported_states_response(
156185
CHECK(stream != NULL);
157186
STREAM_TO_ARRAY(supported_states, stream, (int)supported_states_size);
158187

188+
int ijk;
189+
for (ijk = 0; ijk < ((int)supported_states_size); ijk++) LOG_DEBUG(LOG_TAG, "supported state 0x%x is 0x%x", ijk, supported_states[ijk]);
190+
191+
char unsupport_bitmask_str[PROPERTY_VALUE_MAX];
192+
property_get("persist.sys.bt.unsupport.states", unsupport_bitmask_str, "0");
193+
194+
unsigned int len = strlen(unsupport_bitmask_str);
195+
uint8_t unsupport_bitmask[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
196+
unsigned int c;
197+
198+
for (c = 0; c < len; c++) {
199+
if (unsupport_bitmask_str[c] == '1') {
200+
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.
201+
} else if (unsupport_bitmask_str[c] != '0') {
202+
LOG_ERROR(LOG_TAG, "invalid characters in bitmask; skipping %c", unsupport_bitmask_str[c]);
203+
goto out;
204+
}
205+
}
206+
207+
208+
for (c = 0; c < supported_states_size; c++)
209+
supported_states[c] &= unsupport_bitmask[c];
210+
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]);
211+
out:
212+
for (ijk = 0; ijk < ((int)supported_states_size); ijk++) LOG_ERROR(LOG_TAG, "supported state 0x%x is 0x%x", ijk, supported_states[ijk]);
213+
LOG_DEBUG(LOG_TAG, "supported_states array done");
159214
buffer_allocator->free(response);
160215
}
161216

0 commit comments

Comments
 (0)