Skip to content

Commit bf20286

Browse files
perform attribute writes directly, including offset
1 parent cde0e6b commit bf20286

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

connectivity/FEATURE_BLE/libraries/ble-api-implementation/source/GattServerImpl.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,24 @@ uint8_t GattServer::atts_write_cb(
991991
{
992992
uint8_t err;
993993

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();
9971012
}
9981013

9991014
GattWriteCallbackParams::WriteOp_t writeOp;
@@ -1043,15 +1058,18 @@ uint8_t GattServer::atts_write_cb(
10431058
}
10441059
}
10451060

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+
}
10551073

10561074
return ATT_SUCCESS;
10571075
}

0 commit comments

Comments
 (0)