@@ -23,6 +23,8 @@ typedef struct {
2323 uint16_t connection_handle ;
2424 uint8_t adv_svc_uuid_len ;
2525 uint8_t adv_svc_uuid [20 ];
26+ uint8_t mfg_data_len ;
27+ uint8_t mfg_data [20 ];
2628 char * adv_name ;
2729} GapSvc ;
2830
@@ -198,8 +200,10 @@ BleEventFlowStatus ble_event_app_notification(void* pckt) {
198200 gap -> service .connection_handle = event -> Connection_Handle ;
199201
200202 gap_verify_connection_parameters (gap );
201- // Start pairing by sending security request
202- aci_gap_slave_security_req (event -> Connection_Handle );
203+ if (gap -> config -> pairing_method != GapPairingNone ) {
204+ // Start pairing by sending security request
205+ aci_gap_slave_security_req (event -> Connection_Handle );
206+ }
203207 } break ;
204208
205209 default :
@@ -321,6 +325,14 @@ static void set_advertisment_service_uid(uint8_t* uid, uint8_t uid_len) {
321325 gap -> service .adv_svc_uuid_len += uid_len ;
322326}
323327
328+ static void set_manufacturer_data (uint8_t * mfg_data , uint8_t mfg_data_len ) {
329+ furi_check (mfg_data_len < sizeof (gap -> service .mfg_data ) - 2 );
330+ gap -> service .mfg_data [0 ] = mfg_data_len + 1 ;
331+ gap -> service .mfg_data [1 ] = AD_TYPE_MANUFACTURER_SPECIFIC_DATA ;
332+ memcpy (& gap -> service .mfg_data [gap -> service .mfg_data_len ], mfg_data , mfg_data_len );
333+ gap -> service .mfg_data_len += mfg_data_len ;
334+ }
335+
324336static void gap_init_svc (Gap * gap ) {
325337 tBleStatus status ;
326338 uint32_t srd_bd_addr [2 ];
@@ -440,6 +452,11 @@ static void gap_advertise_start(GapState new_state) {
440452 FURI_LOG_D (TAG , "set_non_discoverable success" );
441453 }
442454 }
455+
456+ if (gap -> service .mfg_data_len > 0 ) {
457+ hci_le_set_scan_response_data (gap -> service .mfg_data_len , gap -> service .mfg_data );
458+ }
459+
443460 // Configure advertising
444461 status = aci_gap_set_discoverable (
445462 ADV_IND ,
@@ -550,11 +567,26 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) {
550567 gap -> is_secure = false;
551568 gap -> negotiation_round = 0 ;
552569
553- uint8_t adv_service_uid [2 ];
554- gap -> service .adv_svc_uuid_len = 1 ;
555- adv_service_uid [0 ] = gap -> config -> adv_service_uuid & 0xff ;
556- adv_service_uid [1 ] = gap -> config -> adv_service_uuid >> 8 ;
557- set_advertisment_service_uid (adv_service_uid , sizeof (adv_service_uid ));
570+ if (gap -> config -> mfg_data_len > 0 ) {
571+ // Offset by 2 for length + AD_TYPE_MANUFACTURER_SPECIFIC_DATA
572+ gap -> service .mfg_data_len = 2 ;
573+ set_manufacturer_data (gap -> config -> mfg_data , gap -> config -> mfg_data_len );
574+ }
575+
576+ if (gap -> config -> adv_service .UUID_Type == UUID_TYPE_16 ) {
577+ uint8_t adv_service_uid [2 ];
578+ gap -> service .adv_svc_uuid_len = 1 ;
579+ adv_service_uid [0 ] = gap -> config -> adv_service .Service_UUID_16 & 0xff ;
580+ adv_service_uid [1 ] = gap -> config -> adv_service .Service_UUID_16 >> 8 ;
581+ set_advertisment_service_uid (adv_service_uid , sizeof (adv_service_uid ));
582+ } else if (gap -> config -> adv_service .UUID_Type == UUID_TYPE_128 ) {
583+ gap -> service .adv_svc_uuid_len = 1 ;
584+ set_advertisment_service_uid (
585+ gap -> config -> adv_service .Service_UUID_128 ,
586+ sizeof (gap -> config -> adv_service .Service_UUID_128 ));
587+ } else {
588+ furi_crash ("Invalid UUID type" );
589+ }
558590
559591 // Set callback
560592 gap -> on_event_cb = on_event_cb ;
0 commit comments