@@ -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,84 @@ 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
+ constexpr uuid_t custom_service = { .size = RSI_BLE_MATTER_CUSTOM_SERVICE_SIZE,
119
+ .val = { .val16 = RSI_BLE_MATTER_CUSTOM_SERVICE_VALUE_16 } };
120
+ uint8_t data[RSI_BLE_MATTER_CUSTOM_SERVICE_DATA_LENGTH] = { RSI_BLE_MATTER_CUSTOM_SERVICE_DATA };
121
+
122
+ constexpr uuid_t custom_characteristic_RX = { .size = RSI_BLE_CUSTOM_CHARACTERISTIC_RX_SIZE,
123
+ .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_RESERVED },
124
+ .val = { .val128 = {
125
+ .data1 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_1 },
126
+ .data2 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_2 },
127
+ .data3 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_3 },
128
+ .data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_4 } } } };
129
+
130
+ rsi_ble_resp_add_serv_t new_serv_resp = { 0 };
131
+ rsi_ble_add_service (custom_service, &new_serv_resp);
132
+
133
+ // Adding custom characteristic declaration to the custom service
134
+ SilabsBleWrapper::rsi_ble_add_char_serv_att (
135
+ new_serv_resp.serv_handler , new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_RX_ATTRIBUTE_HANDLE_LOCATION,
136
+ RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ, // Set read, write, write without response
137
+ new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_RX_VALUE_HANDLE_LOCATION, custom_characteristic_RX);
138
+
139
+ // Adding characteristic value attribute to the service
140
+ SilabsBleWrapper::rsi_ble_add_char_val_att (
141
+ new_serv_resp.serv_handler , new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_RX_VALUE_HANDLE_LOCATION,
142
+ custom_characteristic_RX,
143
+ RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ, // Set read, write, write without response
144
+ data, sizeof (data), ATT_REC_IN_HOST);
145
+
146
+ constexpr uuid_t custom_characteristic_TX = { .size = RSI_BLE_CUSTOM_CHARACTERISTIC_TX_SIZE,
147
+ .reserved = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_RESERVED },
148
+ .val = { .val128 = {
149
+ .data1 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_1 },
150
+ .data2 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_2 },
151
+ .data3 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_3 },
152
+ .data4 = { RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_4 } } } };
153
+
154
+ // Adding custom characteristic declaration to the custom service
155
+ SilabsBleWrapper::rsi_ble_add_char_serv_att (
156
+ new_serv_resp.serv_handler , new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_ATTRIBUTE_HANDLE_LOCATION,
157
+ RSI_BLE_ATT_PROPERTY_WRITE_NO_RESPONSE | RSI_BLE_ATT_PROPERTY_WRITE | RSI_BLE_ATT_PROPERTY_READ |
158
+ RSI_BLE_ATT_PROPERTY_NOTIFY | RSI_BLE_ATT_PROPERTY_INDICATE, // Set read, write, write without response
159
+ new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION, custom_characteristic_TX);
160
+
161
+ // Adding characteristic value attribute to the service
162
+ rsi_ble_measurement_hndl = new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION;
163
+
164
+ // Adding characteristic value attribute to the service
165
+ rsi_ble_gatt_server_client_config_hndl =
166
+ new_serv_resp.start_handle + RSI_BLE_CHARACTERISTIC_TX_GATT_SERVER_CLIENT_HANDLE_LOCATION;
167
+
168
+ SilabsBleWrapper::rsi_ble_add_char_val_att (new_serv_resp.serv_handler , rsi_ble_measurement_hndl, custom_characteristic_TX,
169
+ RSI_BLE_ATT_PROPERTY_WRITE_NO_RESPONSE | RSI_BLE_ATT_PROPERTY_WRITE |
170
+ RSI_BLE_ATT_PROPERTY_READ | RSI_BLE_ATT_PROPERTY_NOTIFY |
171
+ RSI_BLE_ATT_PROPERTY_INDICATE, // Set read, write, write without response
172
+ data, sizeof (data), ATT_REC_MAINTAIN_IN_HOST);
173
+ }
174
+
114
175
} // namespace
115
176
116
177
BLEManagerImpl BLEManagerImpl::sInstance ;
@@ -120,15 +181,14 @@ void BLEManagerImpl::ProcessEvent(SilabsBleWrapper::BleEvent_t inEvent)
120
181
switch (inEvent.eventType )
121
182
{
122
183
case SilabsBleWrapper::BleEventType::RSI_BLE_CONN_EVENT: {
123
- BLEMgrImpl ().HandleConnectEvent (( inEvent.eventData ) );
184
+ BLEMgrImpl ().HandleConnectEvent (inEvent.eventData );
124
185
// 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,
186
+ rsi_ble_conn_params_update (inEvent.eventData . resp_enh_conn .dev_addr , BLE_MIN_CONNECTION_INTERVAL_MS,
126
187
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);
188
+ rsi_ble_set_data_len (inEvent.eventData . resp_enh_conn .dev_addr , RSI_BLE_TX_OCTETS, RSI_BLE_TX_TIME);
128
189
129
190
// 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 ;
191
+ memcpy (dev_address, inEvent.eventData .resp_enh_conn .dev_addr , RSI_DEV_ADDR_LEN);
132
192
}
133
193
break ;
134
194
case SilabsBleWrapper::BleEventType::RSI_BLE_DISCONN_EVENT: {
@@ -143,7 +203,7 @@ void BLEManagerImpl::ProcessEvent(SilabsBleWrapper::BleEvent_t inEvent)
143
203
break ;
144
204
case SilabsBleWrapper::BleEventType::RSI_BLE_EVENT_GATT_RD: {
145
205
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
146
- if (inEvent.eventData -> rsi_ble_read_req ->type == 0 )
206
+ if (inEvent.eventData . rsi_ble_read_req ->type == 0 )
147
207
{
148
208
BLEMgrImpl ().HandleC3ReadRequest (inEvent.eventData );
149
209
}
@@ -220,10 +280,10 @@ void BLEManagerImpl::sl_ble_init()
220
280
SilabsBleWrapper::rsi_ble_on_event_indication_confirmation, NULL );
221
281
222
282
// Exchange of GATT info with BLE stack
223
- SilabsBleWrapper:: rsi_ble_add_matter_service ();
283
+ rsi_ble_add_matter_service ();
224
284
rsi_ble_set_random_address_with_value (randomAddrBLE);
225
285
226
- sInstance .sBleEventQueue = osMessageQueueNew (WFX_QUEUE_SIZE, sizeof (WfxEvent_t ), NULL );
286
+ sInstance .sBleEventQueue = osMessageQueueNew (WFX_QUEUE_SIZE, sizeof (SilabsBleWrapper::BleEvent_t ), NULL );
227
287
VerifyOrDie (sInstance .sBleEventQueue != nullptr );
228
288
229
289
chip::DeviceLayer::Internal::BLEMgrImpl ().HandleBootEvent ();
@@ -440,7 +500,7 @@ CHIP_ERROR BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const Chi
440
500
PacketBufferHandle data)
441
501
{
442
502
int32_t status = 0 ;
443
- status = rsi_ble_indicate_value (dev_address, ble_measurement_hndl , data->DataLength (), data->Start ());
503
+ status = rsi_ble_indicate_value (dev_address, rsi_ble_measurement_hndl , data->DataLength (), data->Start ());
444
504
if (status != RSI_SUCCESS)
445
505
{
446
506
ChipLogProgress (DeviceLayer, " indication failed with error code %lx " , status);
@@ -734,9 +794,9 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void)
734
794
return err;
735
795
}
736
796
737
- void BLEManagerImpl::UpdateMtu (SilabsBleWrapper::sl_wfx_msg_t * evt)
797
+ void BLEManagerImpl::UpdateMtu (const SilabsBleWrapper::sl_wfx_msg_t & evt)
738
798
{
739
- CHIPoBLEConState * bleConnState = GetConnectionState (evt-> connectionHandle );
799
+ CHIPoBLEConState * bleConnState = GetConnectionState (evt. connectionHandle );
740
800
if (bleConnState != NULL )
741
801
{
742
802
// bleConnState->MTU is a 10-bit field inside a uint16_t. We're
@@ -748,10 +808,10 @@ void BLEManagerImpl::UpdateMtu(SilabsBleWrapper::sl_wfx_msg_t * evt)
748
808
// TODO: https://github.com/project-chip/connectedhomeip/issues/2569
749
809
// tracks making this safe with a check or explaining why no check
750
810
// is needed.
751
- ChipLogProgress (DeviceLayer, " DriveBLEState UpdateMtu %d" , evt-> rsi_ble_mtu .mtu_size );
811
+ ChipLogProgress (DeviceLayer, " DriveBLEState UpdateMtu %d" , evt. rsi_ble_mtu .mtu_size );
752
812
#pragma GCC diagnostic push
753
813
#pragma GCC diagnostic ignored "-Wconversion"
754
- bleConnState->mtu = evt-> rsi_ble_mtu .mtu_size ;
814
+ bleConnState->mtu = evt. rsi_ble_mtu .mtu_size ;
755
815
#pragma GCC diagnostic pop
756
816
;
757
817
}
@@ -763,14 +823,13 @@ void BLEManagerImpl::HandleBootEvent(void)
763
823
PlatformMgr ().ScheduleWork (DriveBLEState, 0 );
764
824
}
765
825
766
- void BLEManagerImpl::HandleConnectEvent (SilabsBleWrapper::sl_wfx_msg_t * evt)
826
+ void BLEManagerImpl::HandleConnectEvent (const SilabsBleWrapper::sl_wfx_msg_t & evt)
767
827
{
768
- AddConnection (evt-> connectionHandle , evt-> bondingHandle );
828
+ AddConnection (evt. connectionHandle , evt. bondingHandle );
769
829
PlatformMgr ().ScheduleWork (DriveBLEState, 0 );
770
830
}
771
831
772
- // TODO:: Implementation need to be done.
773
- void BLEManagerImpl::HandleConnectionCloseEvent (SilabsBleWrapper::sl_wfx_msg_t * evt)
832
+ void BLEManagerImpl::HandleConnectionCloseEvent (const SilabsBleWrapper::sl_wfx_msg_t & evt)
774
833
{
775
834
uint8_t connHandle = 1 ;
776
835
@@ -780,7 +839,7 @@ void BLEManagerImpl::HandleConnectionCloseEvent(SilabsBleWrapper::sl_wfx_msg_t *
780
839
event.Type = DeviceEventType::kCHIPoBLEConnectionError ;
781
840
event.CHIPoBLEConnectionError .ConId = connHandle;
782
841
783
- switch (evt-> reason )
842
+ switch (evt. reason )
784
843
{
785
844
786
845
case RSI_BT_CTRL_REMOTE_USER_TERMINATED:
@@ -792,7 +851,7 @@ void BLEManagerImpl::HandleConnectionCloseEvent(SilabsBleWrapper::sl_wfx_msg_t *
792
851
event.CHIPoBLEConnectionError .Reason = BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT;
793
852
}
794
853
795
- ChipLogProgress (DeviceLayer, " BLE GATT connection closed (con %u, reason %x)" , connHandle, evt-> reason );
854
+ ChipLogProgress (DeviceLayer, " BLE GATT connection closed (con %u, reason %x)" , connHandle, evt. reason );
796
855
797
856
PlatformMgr ().PostEventOrDie (&event);
798
857
@@ -804,11 +863,11 @@ void BLEManagerImpl::HandleConnectionCloseEvent(SilabsBleWrapper::sl_wfx_msg_t *
804
863
}
805
864
}
806
865
807
- void BLEManagerImpl::HandleWriteEvent (SilabsBleWrapper::sl_wfx_msg_t * evt)
866
+ void BLEManagerImpl::HandleWriteEvent (const SilabsBleWrapper::sl_wfx_msg_t & evt)
808
867
{
809
- ChipLogProgress (DeviceLayer, " Char Write Req, packet type %d" , evt-> rsi_ble_write .pkt_type );
868
+ ChipLogProgress (DeviceLayer, " Char Write Req, packet type %d" , evt. rsi_ble_write .pkt_type );
810
869
811
- if (evt-> rsi_ble_write .handle [0 ] == (uint8_t ) evt-> rsi_ble_gatt_server_client_config_hndl ) // TODO:: compare the handle exactly
870
+ if (evt. rsi_ble_write .handle [0 ] == (uint8_t ) rsi_ble_gatt_server_client_config_hndl) // TODO:: compare the handle exactly
812
871
{
813
872
HandleTXCharCCCDWrite (evt);
814
873
}
@@ -818,23 +877,22 @@ void BLEManagerImpl::HandleWriteEvent(SilabsBleWrapper::sl_wfx_msg_t * evt)
818
877
}
819
878
}
820
879
821
- // TODO:: Need to implement this
822
- void BLEManagerImpl::HandleTXCharCCCDWrite (SilabsBleWrapper::sl_wfx_msg_t * evt)
880
+ void BLEManagerImpl::HandleTXCharCCCDWrite (const SilabsBleWrapper::sl_wfx_msg_t & evt)
823
881
{
824
882
CHIP_ERROR err = CHIP_NO_ERROR;
825
883
bool isIndicationEnabled = false ;
826
884
ChipDeviceEvent event;
827
885
CHIPoBLEConState * bleConnState;
828
886
829
- bleConnState = GetConnectionState (evt-> connectionHandle );
887
+ bleConnState = GetConnectionState (evt. connectionHandle );
830
888
VerifyOrExit (bleConnState != NULL , err = CHIP_ERROR_NO_MEMORY);
831
889
832
890
// Determine if the client is enabling or disabling notification/indication.
833
- if (evt-> rsi_ble_write .att_value [0 ] != 0 )
891
+ if (evt. rsi_ble_write .att_value [0 ] != 0 )
834
892
{
835
893
isIndicationEnabled = true ;
836
894
}
837
- ChipLogProgress (DeviceLayer, " HandleTXcharCCCDWrite - Config Flags value : %d" , evt-> rsi_ble_write .att_value [0 ]);
895
+ ChipLogProgress (DeviceLayer, " HandleTXcharCCCDWrite - Config Flags value : %d" , evt. rsi_ble_write .att_value [0 ]);
838
896
ChipLogProgress (DeviceLayer, " CHIPoBLE %s received" , isIndicationEnabled ? " subscribe" : " unsubscribe" );
839
897
840
898
if (isIndicationEnabled)
@@ -864,13 +922,13 @@ void BLEManagerImpl::HandleTXCharCCCDWrite(SilabsBleWrapper::sl_wfx_msg_t * evt)
864
922
}
865
923
}
866
924
867
- void BLEManagerImpl::HandleRXCharWrite (SilabsBleWrapper::sl_wfx_msg_t * evt)
925
+ void BLEManagerImpl::HandleRXCharWrite (const SilabsBleWrapper::sl_wfx_msg_t & evt)
868
926
{
869
927
uint8_t conId = 1 ;
870
928
CHIP_ERROR err = CHIP_NO_ERROR;
871
929
System::PacketBufferHandle buf;
872
- uint16_t writeLen = evt-> rsi_ble_write .length ;
873
- uint8_t * data = (uint8_t *) evt-> rsi_ble_write .att_value ;
930
+ uint16_t writeLen = evt. rsi_ble_write .length ;
931
+ uint8_t * data = (uint8_t *) evt. rsi_ble_write .att_value ;
874
932
875
933
// Copy the data to a packet buffer.
876
934
buf = System::PacketBufferHandle::NewWithData (data, writeLen, 0 , 0 );
@@ -997,9 +1055,9 @@ CHIP_ERROR BLEManagerImpl::EncodeAdditionalDataTlv()
997
1055
return err;
998
1056
}
999
1057
1000
- void BLEManagerImpl::HandleC3ReadRequest (SilabsBleWrapper::sl_wfx_msg_t * evt)
1058
+ void BLEManagerImpl::HandleC3ReadRequest (const SilabsBleWrapper::sl_wfx_msg_t & evt)
1001
1059
{
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 ,
1060
+ 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
1061
GATT_READ_ZERO_OFFSET, sInstance .c3AdditionalDataBufferHandle ->DataLength (),
1004
1062
sInstance .c3AdditionalDataBufferHandle ->Start ());
1005
1063
if (ret != SL_STATUS_OK)
0 commit comments