@@ -78,6 +78,33 @@ static attribute_handle_range_t to_ble_handle_range(const ble_gattc_handle_range
78
78
return result;
79
79
}
80
80
81
+ /* *
82
+ * Convert an error from the softdevice into a ble_error_t
83
+ */
84
+ static ble_error_t convert_sd_error (uint32_t err)
85
+ {
86
+ switch (err) {
87
+ case NRF_SUCCESS:
88
+ return BLE_ERROR_NONE;
89
+ case NRF_ERROR_INVALID_PARAM:
90
+ case BLE_ERROR_INVALID_CONN_HANDLE:
91
+ case NRF_ERROR_INVALID_ADDR:
92
+ return BLE_ERROR_INVALID_PARAM;
93
+ case NRF_ERROR_INVALID_STATE:
94
+ return BLE_ERROR_INVALID_STATE;
95
+ case NRF_ERROR_DATA_SIZE:
96
+ return BLE_ERROR_PARAM_OUT_OF_RANGE;
97
+ case BLE_ERROR_NO_TX_PACKETS:
98
+ return BLE_ERROR_NO_MEM;
99
+ case NRF_ERROR_BUSY:
100
+ return BLE_STACK_BUSY;
101
+ case NRF_ERROR_NO_MEM:
102
+ return BLE_ERROR_NO_MEM;
103
+ default :
104
+ return BLE_ERROR_UNSPECIFIED;
105
+ }
106
+ }
107
+
81
108
/* *
82
109
* Convert a UUID into a ble_uuid_t .
83
110
* If the UUID is a 128 bit one then it is registered into the softdevice.
@@ -101,54 +128,19 @@ static ble_error_t to_nordic_uuid(const UUID &uuid, ble_uuid_t &nordic_uuid)
101
128
memcpy (uuid128.uuid128 , uuid.getBaseUUID (), sizeof (uuid128.uuid128 ));
102
129
103
130
// UUID not found, try to register it
104
- err = sd_ble_uuid_vs_add (
105
- &uuid128,
106
- &nordic_uuid.type
107
- );
108
-
109
- switch (err) {
110
- case NRF_SUCCESS:
111
- nordic_uuid.uuid = bytes_to_u16 (uuid.getBaseUUID () + 12 );
112
- return BLE_ERROR_NONE;
113
- case NRF_ERROR_INVALID_ADDR:
114
- return BLE_ERROR_INVALID_PARAM;
115
- case NRF_ERROR_NO_MEM:
116
- return BLE_ERROR_NO_MEM;
117
- default :
118
- return BLE_ERROR_UNSPECIFIED;
131
+ err = sd_ble_uuid_vs_add (&uuid128, &nordic_uuid.type );
132
+ if (err == NRF_SUCCESS) {
133
+ nordic_uuid.uuid = bytes_to_u16 (uuid.getBaseUUID () + 12 );
119
134
}
135
+
136
+ return convert_sd_error (err);
120
137
} else {
121
138
nordic_uuid.type = BLE_UUID_TYPE_BLE;
122
139
nordic_uuid.uuid = uuid.getShortUUID ();
123
140
return BLE_ERROR_NONE;
124
141
}
125
142
}
126
143
127
- /* *
128
- * Convert an error from the softdevice into a ble_error_t
129
- */
130
- static ble_error_t convert_sd_error (uint32_t err)
131
- {
132
- switch (err) {
133
- case NRF_SUCCESS:
134
- return BLE_ERROR_NONE;
135
- case NRF_ERROR_INVALID_PARAM:
136
- case BLE_ERROR_INVALID_CONN_HANDLE:
137
- case NRF_ERROR_INVALID_ADDR:
138
- return BLE_ERROR_INVALID_PARAM;
139
- case NRF_ERROR_INVALID_STATE:
140
- return BLE_ERROR_INVALID_STATE;
141
- case NRF_ERROR_DATA_SIZE:
142
- return BLE_ERROR_PARAM_OUT_OF_RANGE;
143
- case BLE_ERROR_NO_TX_PACKETS:
144
- return BLE_ERROR_NO_MEM;
145
- case NRF_ERROR_BUSY:
146
- return BLE_STACK_BUSY;
147
- default :
148
- return BLE_ERROR_UNSPECIFIED;
149
- }
150
- }
151
-
152
144
/* *
153
145
* Convert an attribute error code from the softdevice into a valid ATT error.
154
146
*/
@@ -186,6 +178,7 @@ ble_error_t nRF5XGattClient::initialize()
186
178
ble_error_t nRF5XGattClient::exchange_mtu (connection_handle_t connection)
187
179
{
188
180
// Note: Not supported by the current softdevice
181
+ // FIXME: implement when SD 140 5.x.x is present
189
182
return BLE_ERROR_NOT_IMPLEMENTED;
190
183
}
191
184
@@ -361,7 +354,7 @@ ble_error_t nRF5XGattClient::execute_write_queue(
361
354
* the peer. It must be implemented by Procedure derived classes.
362
355
* - handle: Event handler that process ble events comming from the softdevice.
363
356
* This function drive the procedure flow and must be implemented by
364
- * Procedure childs .
357
+ * Procedure derived classes .
365
358
* - terminate: end the procedure and forward the result to the GattClient
366
359
* event handle.
367
360
*
@@ -422,7 +415,7 @@ struct nRF5XGattClient::GattProcedure {
422
415
* It initiate a single request to the peer and excepts a single response. This
423
416
* kind of procedure doesn't requires extra processing step.
424
417
*
425
- * Given that such procedure expect a single event type from the soft device,
418
+ * Given that such procedure expects a single event type from the soft device,
426
419
* error handling can be generalized.
427
420
*/
428
421
struct nRF5XGattClient ::RegularGattProcedure : GattProcedure {
@@ -675,6 +668,9 @@ struct nRF5XGattClient::DiscoverPrimaryServiceProcedure : GattProcedure {
675
668
}
676
669
}
677
670
671
+ // Hold read by group type response of services with 128 bit UUID.
672
+ // The response is composed of the service attribute handle (2 bytes), the
673
+ // end group handle (2 bytes) and the service UUID (16 bytes).
678
674
typedef uint8_t packed_discovery_response_t [20 ];
679
675
680
676
packed_discovery_response_t * response;
0 commit comments