File tree Expand file tree Collapse file tree 1 file changed +30
-12
lines changed
connectivity/FEATURE_BLE/libraries/ble-api-implementation/source Expand file tree Collapse file tree 1 file changed +30
-12
lines changed Original file line number Diff line number Diff line change @@ -991,9 +991,24 @@ uint8_t GattServer::atts_write_cb(
991
991
{
992
992
uint8_t err;
993
993
994
- /* TODO: offset is not handled properly */
995
- if ((err = AttsSetAttr (handle, len, pValue)) != ATT_SUCCESS) {
996
- return err;
994
+ /* we don't write anything during the prepare phase */
995
+ bool write_happened = (operation != ATT_PDU_PREP_WRITE_REQ);
996
+
997
+ if (len > pAttr->maxLen ) {
998
+ return ATT_ERR_LENGTH;
999
+ }
1000
+
1001
+ if (write_happened) {
1002
+ WsfTaskLock ();
1003
+
1004
+ memcpy ((pAttr->pValue + offset), pValue, len);
1005
+
1006
+ /* write the length if variable length attribute */
1007
+ if ((pAttr->settings & ATTS_SET_VARIABLE_LEN) != 0 ) {
1008
+ *(pAttr->pLen ) = offset + len;
1009
+ }
1010
+
1011
+ WsfTaskUnlock ();
997
1012
}
998
1013
999
1014
GattWriteCallbackParams::WriteOp_t writeOp;
@@ -1043,15 +1058,18 @@ uint8_t GattServer::atts_write_cb(
1043
1058
}
1044
1059
}
1045
1060
1046
- GattWriteCallbackParams write_params = {
1047
- connId,
1048
- handle,
1049
- writeOp,
1050
- offset,
1051
- len,
1052
- pValue
1053
- };
1054
- getInstance ().handleDataWrittenEvent (&write_params);
1061
+ if (write_happened) {
1062
+ GattWriteCallbackParams write_params = {
1063
+ connId,
1064
+ handle,
1065
+ writeOp,
1066
+ offset,
1067
+ len,
1068
+ pValue
1069
+ };
1070
+
1071
+ getInstance ().handleDataWrittenEvent (&write_params);
1072
+ }
1055
1073
1056
1074
return ATT_SUCCESS;
1057
1075
}
You can’t perform that action at this time.
0 commit comments