@@ -17,6 +17,12 @@ import (
17
17
"unsafe"
18
18
)
19
19
20
+ // TODO: @rdnt cleanup
21
+ //var (
22
+ // dataLenParams = &C.ble_gap_data_length_params_t{}
23
+ // dataLenLimitation = &C.ble_gap_data_length_limitation_t{}
24
+ //)
25
+
20
26
func handleEvent () {
21
27
id := eventBuf .header .evt_id
22
28
switch {
@@ -63,7 +69,7 @@ func handleEvent() {
63
69
// because it would need to be reconfigured as a non-connectable
64
70
// advertisement. That's left as a future addition, if
65
71
// necessary.
66
- C .sd_ble_gap_adv_start (defaultAdvertisement .handle , C . BLE_CONN_CFG_TAG_DEFAULT )
72
+ C .sd_ble_gap_adv_start (defaultAdvertisement .handle , connCfgTag )
67
73
}
68
74
device := Device {
69
75
connectionHandle : gapEvent .conn_handle ,
@@ -159,7 +165,16 @@ func handleEvent() {
159
165
case C .BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST :
160
166
// This event is generated by some devices. While we could support
161
167
// larger MTUs, this default MTU is supported everywhere.
162
- C .sd_ble_gatts_exchange_mtu_reply (gattsEvent .conn_handle , C .BLE_GATT_ATT_MTU_DEFAULT )
168
+ rsp := gattsEvent .params .unionfield_exchange_mtu_request ()
169
+ effectiveMtu := min (DefaultAdapter .cfg .Gatt .AttMtu , uint16 (rsp .client_rx_mtu ))
170
+ if debug {
171
+ println ("mtu exchange requested. self:" , DefaultAdapter .cfg .Gatt .AttMtu , ", peer:" , rsp .client_rx_mtu , ", effective:" , effectiveMtu )
172
+ }
173
+
174
+ var errCode = C .sd_ble_gatts_exchange_mtu_reply (gattsEvent .conn_handle , C .uint16_t (effectiveMtu ))
175
+ if debug {
176
+ println ("mtu exchange replied, err:" , Error (errCode ).Error ())
177
+ }
163
178
case C .BLE_GATTS_EVT_HVN_TX_COMPLETE :
164
179
// ignore confirmation of a notification successfully sent
165
180
default :
@@ -255,6 +270,12 @@ func handleEvent() {
255
270
}
256
271
}
257
272
}
273
+
274
+ case C .BLE_GATTC_EVT_EXCHANGE_MTU_RSP :
275
+ if debug {
276
+ rsp := gattcEvent .params .unionfield_exchange_mtu_rsp ()
277
+ println ("mtu exchanged, effective mtu:" , rsp .server_rx_mtu )
278
+ }
258
279
default :
259
280
if debug {
260
281
println ("unknown GATTC event:" , id , id - C .BLE_GATTC_EVT_BASE )
@@ -266,3 +287,10 @@ func handleEvent() {
266
287
}
267
288
}
268
289
}
290
+
291
+ func min (a , b uint16 ) uint16 {
292
+ if a < b {
293
+ return a
294
+ }
295
+ return b
296
+ }
0 commit comments