-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathwfx_sl_ble_init.h
143 lines (130 loc) · 6.01 KB
/
wfx_sl_ble_init.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*******************************************************************************
* @file wfx_sl_ble_init.h
* @brief
*******************************************************************************
* # License
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* Copyright (c) 2022 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
// BLE include file to refer BLE APIs
#include "ble_config.h"
#include "cmsis_os2.h"
#include <stdbool.h>
#include <string.h>
extern "C" {
#include <rsi_ble.h>
#include <rsi_ble_apis.h>
#include <rsi_ble_common_config.h>
#include <rsi_bt_common.h>
#include <rsi_bt_common_apis.h>
#include <rsi_common_apis.h>
}
#define ATT_REC_IN_HOST (0)
#define WFX_QUEUE_SIZE 10
#define RSI_BT_CTRL_REMOTE_USER_TERMINATED (0x4E13)
#define RSI_BT_CTRL_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES (0x4E14)
#define RSI_BT_CTRL_REMOTE_POWERING_OFF (0x4E15)
#define RSI_BT_CTRL_TERMINATED_MIC_FAILURE (0x4E3D)
#define RSI_BT_FAILED_TO_ESTABLISH_CONN (0x4E3E)
#define RSI_BT_INVALID_RANGE (0x4E60)
#define RSI_BLE_MATTER_CUSTOM_SERVICE_UUID (0)
#define RSI_BLE_MATTER_CUSTOM_SERVICE_SIZE (2)
#define RSI_BLE_MATTER_CUSTOM_SERVICE_VALUE_16 (0xFFF6)
#define RSI_BLE_MATTER_CUSTOM_SERVICE_DATA (0x00)
#define RSI_BLE_CUSTOM_CHARACTERISTIC_RX_SIZE (16)
#define RSI_BLE_CUSTOM_CHARACTERISTIC_RX_RESERVED 0x00, 0x00, 0x00
#define RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_1 0x18EE2EF5
#define RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_2 0x263D
#define RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_3 0x4559
#define RSI_BLE_CUSTOM_CHARACTERISTIC_RX_VALUE_128_DATA_4 0x9F, 0x95, 0x9C, 0x4F, 0x11, 0x9D, 0x9F, 0x42
#define RSI_BLE_CHARACTERISTIC_RX_ATTRIBUTE_HANDLE_LOCATION (1)
#define RSI_BLE_CHARACTERISTIC_RX_VALUE_HANDLE_LOCATION (2)
#define RSI_BLE_CUSTOM_CHARACTERISTIC_TX_SIZE (16)
#define RSI_BLE_CUSTOM_CHARACTERISTIC_TX_RESERVED 0x00, 0x00, 0x00
#define RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_1 0x18EE2EF5
#define RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_2 0x263D
#define RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_3 0x4559
#define RSI_BLE_CUSTOM_CHARACTERISTIC_TX_VALUE_128_DATA_4 0x9F, 0x95, 0x9C, 0x4F, 0x12, 0x9D, 0x9F, 0x42
#define RSI_BLE_CHARACTERISTIC_TX_ATTRIBUTE_HANDLE_LOCATION (3)
#define RSI_BLE_CHARACTERISTIC_TX_MEASUREMENT_HANDLE_LOCATION (4)
#define RSI_BLE_CHARACTERISTIC_TX_GATT_SERVER_CLIENT_HANDLE_LOCATION (5)
#ifdef CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
#define RSI_BLE_CUSTOM_CHARACTERISTIC_C3_SIZE (16)
#define RSI_BLE_CUSTOM_CHARACTERISTIC_C3_RESERVED 0x00, 0x00, 0x00
#define RSI_BLE_CUSTOM_CHARACTERISTIC_C3_VALUE_128_DATA_1 0x64630238
#define RSI_BLE_CUSTOM_CHARACTERISTIC_C3_VALUE_128_DATA_2 0x8772
#define RSI_BLE_CUSTOM_CHARACTERISTIC_C3_VALUE_128_DATA_3 0x45f2
#define RSI_BLE_CUSTOM_CHARACTERISTIC_C3_VALUE_128_DATA_4 0x7D, 0xB8, 0x8A, 0x74, 0x04, 0x8F, 0x21, 0x83
#define RSI_BLE_CHARACTERISTIC_C3_ATTRIBUTE_HANDLE_LOCATION (6)
#define RSI_BLE_CHARACTERISTIC_C3_MEASUREMENT_HANDLE_LOCATION (7)
#define RSI_BLE_CHARACTERISTIC_C3_GATT_SERVER_CLIENT_HANDLE_LOCATION (8)
#endif
namespace chip {
namespace DeviceLayer {
namespace Internal {
class SilabsBleWrapper
{
public:
enum class BleEventType : uint8_t
{
RSI_BLE_CONN_EVENT,
RSI_BLE_DISCONN_EVENT,
RSI_BLE_GATT_WRITE_EVENT,
RSI_BLE_MTU_EVENT,
RSI_BLE_GATT_INDICATION_CONFIRMATION,
RSI_BLE_RESP_ATT_VALUE,
RSI_BLE_EVENT_GATT_RD
};
struct sl_wfx_msg_t
{
uint8_t connectionHandle;
uint8_t bondingHandle;
uint16_t reason;
uint16_t event_id;
uint16_t resp_status;
rsi_ble_event_mtu_t rsi_ble_mtu;
rsi_ble_event_write_t rsi_ble_write;
rsi_ble_event_enhance_conn_status_t resp_enh_conn;
rsi_ble_event_disconnect_t * resp_disconnect;
rsi_ble_read_req_t * rsi_ble_read_req;
rsi_ble_set_att_resp_t rsi_ble_event_set_att_rsp;
uint16_t subscribed;
};
struct BleEvent_t
{
BleEventType eventType;
sl_wfx_msg_t eventData;
};
// ALL Ble functions
static void rsi_ble_on_connect_event(rsi_ble_event_conn_status_t * resp_conn);
static void rsi_ble_on_disconnect_event(rsi_ble_event_disconnect_t * resp_disconnect, uint16_t reason);
static void rsi_ble_on_enhance_conn_status_event(rsi_ble_event_enhance_conn_status_t * resp_enh_conn);
static void rsi_ble_on_gatt_write_event(uint16_t event_id, rsi_ble_event_write_t * rsi_ble_write);
static void rsi_ble_on_mtu_event(rsi_ble_event_mtu_t * rsi_ble_mtu);
static void rsi_ble_on_event_indication_confirmation(uint16_t resp_status, rsi_ble_set_att_resp_t * rsi_ble_event_set_att_rsp);
static void rsi_ble_on_read_req_event(uint16_t event_id, rsi_ble_read_req_t * rsi_ble_read_req);
static void rsi_gatt_add_attribute_to_list(rsi_ble_t * p_val, uint16_t handle, uint16_t data_len, uint8_t * data, uuid_t uuid,
uint8_t char_prop);
static void rsi_ble_add_char_serv_att(void * serv_handler, uint16_t handle, uint8_t val_prop, uint16_t att_val_handle,
uuid_t att_val_uuid);
static void rsi_ble_add_char_val_att(void * serv_handler, uint16_t handle, uuid_t att_type_uuid, uint8_t val_prop,
uint8_t * data, uint8_t data_len, uint8_t auth_read);
};
} // namespace Internal
} // namespace DeviceLayer
} // namespace chip