@@ -57,24 +57,7 @@ extern "C" {
57
57
#define BLE_TIMEOUT_MS 400
58
58
#define BLE_SEND_INDICATION_TIMER_PERIOD_MS (5000 )
59
59
60
- // Used to send the Indication Confirmation
61
- uint8_t dev_address[RSI_DEV_ADDR_LEN];
62
- uint16_t ble_measurement_hndl;
63
-
64
60
osSemaphoreId_t sl_rs_ble_init_sem;
65
- osTimerId_t sbleAdvTimeoutTimer;
66
-
67
- static osThreadId_t sBleThread ;
68
- constexpr uint32_t kBleTaskSize = 2048 ;
69
- static uint8_t bleStack[kBleTaskSize ];
70
- static osThread_t sBleTaskControlBlock ;
71
- constexpr osThreadAttr_t kBleTaskAttr = { .name = " rsi_ble" ,
72
- .attr_bits = osThreadDetached,
73
- .cb_mem = &sBleTaskControlBlock ,
74
- .cb_size = osThreadCbSize,
75
- .stack_mem = bleStack,
76
- .stack_size = kBleTaskSize ,
77
- .priority = osPriorityHigh };
78
61
79
62
using namespace ::chip;
80
63
using namespace ::chip::Ble;
@@ -111,6 +94,85 @@ const uint8_t UUID_CHIPoBLEService[] = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00
111
94
0x00 , 0x10 , 0x00 , 0x00 , 0xF6 , 0xFF , 0x00 , 0x00 };
112
95
const uint8_t ShortUUID_CHIPoBLEService[] = { 0xF6 , 0xFF };
113
96
97
+ // Used to send the Indication Confirmation
98
+ uint8_t dev_address[RSI_DEV_ADDR_LEN];
99
+ uint16_t rsi_ble_measurement_hndl;
100
+ uint16_t rsi_ble_gatt_server_client_config_hndl;
101
+
102
+ osTimerId_t sbleAdvTimeoutTimer;
103
+
104
+ osThreadId_t sBleThread ;
105
+ constexpr uint32_t kBleTaskSize = 2560 ;
106
+ uint8_t bleStack[kBleTaskSize ];
107
+ osThread_t sBleTaskControlBlock ;
108
+ constexpr osThreadAttr_t kBleTaskAttr = { .name = " rsi_ble" ,
109
+ .attr_bits = osThreadDetached,
110
+ .cb_mem = &sBleTaskControlBlock ,
111
+ .cb_size = osThreadCbSize,
112
+ .stack_mem = bleStack,
113
+ .stack_size = kBleTaskSize ,
114
+ .priority = osPriorityHigh };
115
+
116
+ void rsi_ble_add_matter_service (void )
117
+ {
118
+ uuid_t custom_service = { RSI_BLE_MATTER_CUSTOM_SERVICE_UUID };
119
+ custom_service.size = RSI_BLE_MATTER_CUSTOM_SERVICE_SIZE;
120
+ custom_service.val .val16 = RSI_BLE_MATTER_CUSTOM_SERVICE_VALUE_16;
121
+ uint8_t data[RSI_BLE_MATTER_CUSTOM_SERVICE_DATA_LENGTH] = { RSI_BLE_MATTER_CUSTOM_SERVICE_DATA };
122
+
123
+ const uuid_t custom_characteristic_RX = { .size = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_SIZE,
124
+ .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_RESERVED },
125
+ .val = {
126
+ .val128 = { .data1 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_1 },
127
+ .data2 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_2 },
128
+ .data3 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_3 },
129
+ .data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_4 } } } };
130
+
131
+ rsi_ble_resp_add_serv_t new_serv_resp = { 0 };
132
+ rsi_ble_add_service (custom_service, &new_serv_resp);
133
+
134
+ // Adding custom characteristic declaration to the custom service
135
+ SilabsBleWrapper::rsi_ble_add_char_serv_att (
136
+ new_serv_resp.serv_handler , new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_RX_ATTRIBUTE_HANDLE_LOCATION,
137
+ RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ, // Set read, write, write without response
138
+ new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_RX_VALUE_HANDLE_LOCATION, custom_characteristic_RX);
139
+
140
+ // Adding characteristic value attribute to the service
141
+ SilabsBleWrapper::rsi_ble_add_char_val_att (
142
+ new_serv_resp.serv_handler , new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_RX_VALUE_HANDLE_LOCATION,
143
+ custom_characteristic_RX,
144
+ RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ, // Set read, write, write without response
145
+ data, sizeof (data), ATT_REC_IN_HOST);
146
+
147
+ const uuid_t custom_characteristic_TX = { .size = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_SIZE,
148
+ .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_RESERVED },
149
+ .val = {
150
+ .val128 = { .data1 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_1 },
151
+ .data2 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_2 },
152
+ .data3 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_3 },
153
+ .data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_4 } } } };
154
+
155
+ // Adding custom characteristic declaration to the custom service
156
+ SilabsBleWrapper::rsi_ble_add_char_serv_att (
157
+ new_serv_resp.serv_handler , new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_ATTRIBUTE_HANDLE_LOCATION,
158
+ RSI_BLE_ATT_PROPERTY_WRITE_NO_RESPONSE | RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ |
159
+ RSI_BLE_ATT_PROPERTY_NOTIFY | RSI_BLE_ATT_PROPERTY_INDICATE, // Set read, write, write without response
160
+ new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION, custom_characteristic_TX);
161
+
162
+ // Adding characteristic value attribute to the service
163
+ rsi_ble_measurement_hndl = new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION;
164
+
165
+ // Adding characteristic value attribute to the service
166
+ rsi_ble_gatt_server_client_config_hndl =
167
+ new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_GATT_SERVER_CLIENT_HANDLE_LOCATION;
168
+
169
+ SilabsBleWrapper::rsi_ble_add_char_val_att (new_serv_resp.serv_handler , rsi_ble_measurement_hndl, custom_characteristic_TX,
170
+ RSI_BLE_ATT_PROPERTY_WRITE_NO_RESPONSE | RSI_BLE_ATT_PROPERTY_WRITE |
171
+ RSI_BLE_ATT_PROPERTY_READ | RSI_BLE_ATT_PROPERTY_NOTIFY |
172
+ RSI_BLE_ATT_PROPERTY_INDICATE, // Set read, write, write without response
173
+ data, sizeof (data), ATT_REC_MAINTAIN_IN_HOST);
174
+ }
175
+
114
176
} // namespace
115
177
116
178
BLEManagerImpl BLEManagerImpl::sInstance ;
@@ -120,15 +182,14 @@ void BLEManagerImpl::ProcessEvent(SilabsBleWrapper::BleEvent_t inEvent)
120
182
switch (inEvent.eventType )
121
183
{
122
184
case SilabsBleWrapper::BleEventType::RSI_BLE_CONN_EVENT: {
123
- BLEMgrImpl ().HandleConnectEvent (( inEvent.eventData ) );
185
+ BLEMgrImpl ().HandleConnectEvent (inEvent.eventData );
124
186
// Requests the connection parameters change with the remote device
125
- rsi_ble_conn_params_update (inEvent.eventData -> resp_enh_conn .dev_addr , BLE_MIN_CONNECTION_INTERVAL_MS,
187
+ rsi_ble_conn_params_update (inEvent.eventData . resp_enh_conn .dev_addr , BLE_MIN_CONNECTION_INTERVAL_MS,
126
188
BLE_MAX_CONNECTION_INTERVAL_MS, BLE_SLAVE_LATENCY_MS, BLE_TIMEOUT_MS);
127
- rsi_ble_set_data_len (inEvent.eventData -> resp_enh_conn .dev_addr , RSI_BLE_TX_OCTETS, RSI_BLE_TX_TIME);
189
+ rsi_ble_set_data_len (inEvent.eventData . resp_enh_conn .dev_addr , RSI_BLE_TX_OCTETS, RSI_BLE_TX_TIME);
128
190
129
191
// Used to send the Indication confirmation
130
- memcpy (dev_address, inEvent.eventData ->resp_enh_conn .dev_addr , RSI_DEV_ADDR_LEN);
131
- ble_measurement_hndl = inEvent.eventData ->rsi_ble_measurement_hndl ;
192
+ memcpy (dev_address, inEvent.eventData .resp_enh_conn .dev_addr , RSI_DEV_ADDR_LEN);
132
193
}
133
194
break ;
134
195
case SilabsBleWrapper::BleEventType::RSI_BLE_DISCONN_EVENT: {
@@ -143,7 +204,7 @@ void BLEManagerImpl::ProcessEvent(SilabsBleWrapper::BleEvent_t inEvent)
143
204
break ;
144
205
case SilabsBleWrapper::BleEventType::RSI_BLE_EVENT_GATT_RD: {
145
206
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
146
- if (inEvent.eventData -> rsi_ble_read_req ->type == 0 )
207
+ if (inEvent.eventData . rsi_ble_read_req ->type == 0 )
147
208
{
148
209
BLEMgrImpl ().HandleC3ReadRequest (inEvent.eventData );
149
210
}
@@ -220,10 +281,10 @@ void BLEManagerImpl::sl_ble_init()
220
281
SilabsBleWrapper::rsi_ble_on_event_indication_confirmation, NULL );
221
282
222
283
// Exchange of GATT info with BLE stack
223
- SilabsBleWrapper:: rsi_ble_add_matter_service ();
284
+ rsi_ble_add_matter_service ();
224
285
rsi_ble_set_random_address_with_value (randomAddrBLE);
225
286
226
- sInstance .sBleEventQueue = osMessageQueueNew (WFX_QUEUE_SIZE, sizeof (WfxEvent_t ), NULL );
287
+ sInstance .sBleEventQueue = osMessageQueueNew (WFX_QUEUE_SIZE, sizeof (SilabsBleWrapper::BleEvent_t ), NULL );
227
288
VerifyOrDie (sInstance .sBleEventQueue != nullptr );
228
289
229
290
chip::DeviceLayer::Internal::BLEMgrImpl ().HandleBootEvent ();
@@ -440,7 +501,7 @@ CHIP_ERROR BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const Chi
440
501
PacketBufferHandle data)
441
502
{
442
503
int32_t status = 0 ;
443
- status = rsi_ble_indicate_value (dev_address, ble_measurement_hndl , data->DataLength (), data->Start ());
504
+ status = rsi_ble_indicate_value (dev_address, rsi_ble_measurement_hndl , data->DataLength (), data->Start ());
444
505
if (status != RSI_SUCCESS)
445
506
{
446
507
ChipLogProgress (DeviceLayer, " indication failed with error code %lx " , status);
@@ -734,9 +795,9 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void)
734
795
return err;
735
796
}
736
797
737
- void BLEManagerImpl::UpdateMtu (SilabsBleWrapper::sl_wfx_msg_t * evt)
798
+ void BLEManagerImpl::UpdateMtu (const SilabsBleWrapper::sl_wfx_msg_t & evt)
738
799
{
739
- CHIPoBLEConState * bleConnState = GetConnectionState (evt-> connectionHandle );
800
+ CHIPoBLEConState * bleConnState = GetConnectionState (evt. connectionHandle );
740
801
if (bleConnState != NULL )
741
802
{
742
803
// bleConnState->MTU is a 10-bit field inside a uint16_t. We're
@@ -748,10 +809,10 @@ void BLEManagerImpl::UpdateMtu(SilabsBleWrapper::sl_wfx_msg_t * evt)
748
809
// TODO: https://github.com/project-chip/connectedhomeip/issues/2569
749
810
// tracks making this safe with a check or explaining why no check
750
811
// is needed.
751
- ChipLogProgress (DeviceLayer, " DriveBLEState UpdateMtu %d" , evt-> rsi_ble_mtu .mtu_size );
812
+ ChipLogProgress (DeviceLayer, " DriveBLEState UpdateMtu %d" , evt. rsi_ble_mtu .mtu_size );
752
813
#pragma GCC diagnostic push
753
814
#pragma GCC diagnostic ignored "-Wconversion"
754
- bleConnState->mtu = evt-> rsi_ble_mtu .mtu_size ;
815
+ bleConnState->mtu = evt. rsi_ble_mtu .mtu_size ;
755
816
#pragma GCC diagnostic pop
756
817
;
757
818
}
@@ -763,14 +824,14 @@ void BLEManagerImpl::HandleBootEvent(void)
763
824
PlatformMgr ().ScheduleWork (DriveBLEState, 0 );
764
825
}
765
826
766
- void BLEManagerImpl::HandleConnectEvent (SilabsBleWrapper::sl_wfx_msg_t * evt)
827
+ void BLEManagerImpl::HandleConnectEvent (const SilabsBleWrapper::sl_wfx_msg_t & evt)
767
828
{
768
- AddConnection (evt-> connectionHandle , evt-> bondingHandle );
829
+ AddConnection (evt. connectionHandle , evt. bondingHandle );
769
830
PlatformMgr ().ScheduleWork (DriveBLEState, 0 );
770
831
}
771
832
772
833
// TODO:: Implementation need to be done.
773
- void BLEManagerImpl::HandleConnectionCloseEvent (SilabsBleWrapper::sl_wfx_msg_t * evt)
834
+ void BLEManagerImpl::HandleConnectionCloseEvent (const SilabsBleWrapper::sl_wfx_msg_t & evt)
774
835
{
775
836
uint8_t connHandle = 1 ;
776
837
@@ -780,7 +841,7 @@ void BLEManagerImpl::HandleConnectionCloseEvent(SilabsBleWrapper::sl_wfx_msg_t *
780
841
event.Type = DeviceEventType::kCHIPoBLEConnectionError ;
781
842
event.CHIPoBLEConnectionError .ConId = connHandle;
782
843
783
- switch (evt-> reason )
844
+ switch (evt. reason )
784
845
{
785
846
786
847
case RSI_BT_CTRL_REMOTE_USER_TERMINATED:
@@ -792,7 +853,7 @@ void BLEManagerImpl::HandleConnectionCloseEvent(SilabsBleWrapper::sl_wfx_msg_t *
792
853
event.CHIPoBLEConnectionError .Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT;
793
854
}
794
855
795
- ChipLogProgress (DeviceLayer, " BLE GATT connection closed (con %u, reason %x)" , connHandle, evt-> reason );
856
+ ChipLogProgress (DeviceLayer, " BLE GATT connection closed (con %u, reason %x)" , connHandle, evt. reason );
796
857
797
858
PlatformMgr ().PostEventOrDie (&event);
798
859
@@ -804,11 +865,11 @@ void BLEManagerImpl::HandleConnectionCloseEvent(SilabsBleWrapper::sl_wfx_msg_t *
804
865
}
805
866
}
806
867
807
- void BLEManagerImpl::HandleWriteEvent (SilabsBleWrapper::sl_wfx_msg_t * evt)
868
+ void BLEManagerImpl::HandleWriteEvent (const SilabsBleWrapper::sl_wfx_msg_t & evt)
808
869
{
809
- ChipLogProgress (DeviceLayer, " Char Write Req, packet type %d" , evt-> rsi_ble_write .pkt_type );
870
+ ChipLogProgress (DeviceLayer, " Char Write Req, packet type %d" , evt. rsi_ble_write .pkt_type );
810
871
811
- if (evt-> rsi_ble_write .handle [0 ] == (uint8_t ) evt-> rsi_ble_gatt_server_client_config_hndl ) // TODO:: compare the handle exactly
872
+ if (evt. rsi_ble_write .handle [0 ] == (uint8_t ) rsi_ble_gatt_server_client_config_hndl) // TODO:: compare the handle exactly
812
873
{
813
874
HandleTXCharCCCDWrite (evt);
814
875
}
@@ -819,22 +880,22 @@ void BLEManagerImpl::HandleWriteEvent(SilabsBleWrapper::sl_wfx_msg_t * evt)
819
880
}
820
881
821
882
// TODO:: Need to implement this
822
- void BLEManagerImpl::HandleTXCharCCCDWrite (SilabsBleWrapper::sl_wfx_msg_t * evt)
883
+ void BLEManagerImpl::HandleTXCharCCCDWrite (const SilabsBleWrapper::sl_wfx_msg_t & evt)
823
884
{
824
885
CHIP_ERROR err = CHIP_NO_ERROR;
825
886
bool isIndicationEnabled = false ;
826
887
ChipDeviceEvent event;
827
888
CHIPoBLEConState * bleConnState;
828
889
829
- bleConnState = GetConnectionState (evt-> connectionHandle );
890
+ bleConnState = GetConnectionState (evt. connectionHandle );
830
891
VerifyOrExit (bleConnState != NULL , err = CHIP_ERROR_NO_MEMORY);
831
892
832
893
// Determine if the client is enabling or disabling notification/indication.
833
- if (evt-> rsi_ble_write .att_value [0 ] != 0 )
894
+ if (evt. rsi_ble_write .att_value [0 ] != 0 )
834
895
{
835
896
isIndicationEnabled = true ;
836
897
}
837
- ChipLogProgress (DeviceLayer, " HandleTXcharCCCDWrite - Config Flags value : %d" , evt-> rsi_ble_write .att_value [0 ]);
898
+ ChipLogProgress (DeviceLayer, " HandleTXcharCCCDWrite - Config Flags value : %d" , evt. rsi_ble_write .att_value [0 ]);
838
899
ChipLogProgress (DeviceLayer, " CHIPoBLE %s received" , isIndicationEnabled ? " subscribe" : " unsubscribe" );
839
900
840
901
if (isIndicationEnabled)
@@ -864,13 +925,13 @@ void BLEManagerImpl::HandleTXCharCCCDWrite(SilabsBleWrapper::sl_wfx_msg_t * evt)
864
925
}
865
926
}
866
927
867
- void BLEManagerImpl::HandleRXCharWrite (SilabsBleWrapper::sl_wfx_msg_t * evt)
928
+ void BLEManagerImpl::HandleRXCharWrite (const SilabsBleWrapper::sl_wfx_msg_t & evt)
868
929
{
869
930
uint8_t conId = 1 ;
870
931
CHIP_ERROR err = CHIP_NO_ERROR;
871
932
System::PacketBufferHandle buf;
872
- uint16_t writeLen = evt-> rsi_ble_write .length ;
873
- uint8_t * data = (uint8_t *) evt-> rsi_ble_write .att_value ;
933
+ uint16_t writeLen = evt. rsi_ble_write .length ;
934
+ uint8_t * data = (uint8_t *) evt. rsi_ble_write .att_value ;
874
935
875
936
// Copy the data to a packet buffer.
876
937
buf = System::PacketBufferHandle::NewWithData (data, writeLen, 0 , 0 );
@@ -997,9 +1058,9 @@ CHIP_ERROR BLEManagerImpl::EncodeAdditionalDataTlv()
997
1058
return err;
998
1059
}
999
1060
1000
- void BLEManagerImpl::HandleC3ReadRequest (SilabsBleWrapper::sl_wfx_msg_t * evt)
1061
+ void BLEManagerImpl::HandleC3ReadRequest (const SilabsBleWrapper::sl_wfx_msg_t & evt)
1001
1062
{
1002
- sl_status_t ret = rsi_ble_gatt_read_response (evt-> rsi_ble_read_req ->dev_addr , GATT_READ_RESP, evt-> rsi_ble_read_req ->handle ,
1063
+ sl_status_t ret = rsi_ble_gatt_read_response (evt. rsi_ble_read_req ->dev_addr , GATT_READ_RESP, evt. rsi_ble_read_req ->handle ,
1003
1064
GATT_READ_ZERO_OFFSET, sInstance .c3AdditionalDataBufferHandle ->DataLength (),
1004
1065
sInstance .c3AdditionalDataBufferHandle ->Start ());
1005
1066
if (ret != SL_STATUS_OK)
0 commit comments