@@ -1124,6 +1124,8 @@ uint8_t GattServer::atts_read_cb(
1124
1124
attsAttr_t *pAttr
1125
1125
)
1126
1126
{
1127
+ uint8_t err = ATT_SUCCESS;
1128
+
1127
1129
char_auth_callback *auth_cb = getInstance ().get_auth_callback (handle);
1128
1130
if (auth_cb && auth_cb->read_cb ) {
1129
1131
GattReadAuthCallbackParams read_auth_params = {
@@ -1148,25 +1150,21 @@ uint8_t GattServer::atts_read_cb(
1148
1150
1149
1151
/* if new data provided copy into the attribute value buffer */
1150
1152
if (read_auth_params.data ) {
1151
- if (read_auth_params.len > pAttr->maxLen || offset >= read_auth_params.len ) {
1152
- tr_error (" Read authorisation callback set length larger than maximum attribute length "
1153
- " or current offset is beyond new length. Cannot copy data" );
1154
1153
1155
- GattReadCallbackParams read_params = {
1156
- connId,
1157
- handle,
1158
- offset,
1159
- read_auth_params.len ,
1160
- read_auth_params.data ,
1161
- BLE_ERROR_INVALID_PARAM,
1162
- };
1163
- getInstance ().handleDataReadEvent (&read_params);
1164
-
1165
- return ATT_ERR_UNLIKELY;
1154
+ if (read_auth_params.len > pAttr->maxLen ) {
1155
+ tr_error (" Read authorisation callback set length larger than maximum attribute length, "
1156
+ " cannot copy data" );
1157
+ err = ATT_ERR_UNLIKELY;
1166
1158
}
1167
1159
1168
1160
memcpy (pAttr->pValue , read_auth_params.data , read_auth_params.len );
1169
1161
*pAttr->pLen = read_auth_params.len ;
1162
+
1163
+ if (read_auth_params.len < offset) {
1164
+ tr_warning (" Read authorisation callback shortened data beyond current offset, "
1165
+ " current read will fail" );
1166
+ err = ATT_ERR_OFFSET;
1167
+ }
1170
1168
}
1171
1169
}
1172
1170
@@ -1181,11 +1179,11 @@ uint8_t GattServer::atts_read_cb(
1181
1179
offset,
1182
1180
*pAttr->pLen ,
1183
1181
pAttr->pValue ,
1184
- /* status */ BLE_ERROR_NONE,
1182
+ /* status */ (err == ATT_SUCCESS) ? BLE_ERROR_NONE : BLE_ERROR_PARAM_OUT_OF_RANGE
1185
1183
};
1186
1184
getInstance ().handleDataReadEvent (&read_params);
1187
1185
1188
- return ATT_SUCCESS ;
1186
+ return err ;
1189
1187
}
1190
1188
1191
1189
uint8_t GattServer::atts_write_cb (
0 commit comments