ble_error_t BlueNRGGattServer::write(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
{
    /* avoid compiler warnings about unused variables */
    (void)localOnly;

    // check that the len of the data to write are compatible with the characteristic
    GattCharacteristic* characteristic = getCharacteristicFromHandle(attributeHandle);
    if (!characteristic) {
        PRINTF("characteristic not found\r\n");
        return BLE_ERROR_INVALID_PARAM;
    }

    // if the attribute handle is the attribute handle of the characteristic value then
    // write the value
    if (attributeHandle == characteristic->getValueHandle()) {
        // assert the len in input is correct for this characteristic
        const GattAttribute& value_attribute = characteristic->getValueAttribute();

        // reject write if the lenght exceed the maximum lenght of this attribute
        if (value_attribute.getMaxLength() < len) {
            PRINTF("invalid variable length: %u, max length is: %u\r\n", len, value_attribute.getMaxLength());
            return BLE_ERROR_INVALID_PARAM;
        }

        // reject write if the attribute size is fixed and the lenght in input is different than the
        // length of the attribute.
        if (value_attribute.hasVariableLength() == false && value_attribute.getMaxLength() != len) {
            PRINTF("invalid fixed length: %u, len should be %u\r\n", len, value_attribute.getMaxLength());
            return BLE_ERROR_INVALID_PARAM;
        }

        tBleStatus ret;

        uint16_t charHandle = characteristic->getValueHandle() - BlueNRGGattServer::CHAR_VALUE_HANDLE;

        PRINTF("updating bleCharacteristic valueHandle=%u,\
                corresponding serviceHandle=%u len=%d\n\r",
                attributeHandle, bleCharHandleMap.find(charHandle)->second, len);

        /*
         * If notifications (or indications) are enabled on that characteristic, a notification (or indication)
         * will be sent to the client after sending this command to the BlueNRG.
         */
        ret = aci_gatt_update_char_value(bleCharHandleMap.find(charHandle)->second, charHandle, 0, len, buffer);

        if (ret != BLE_STATUS_SUCCESS){
          PRINTF("Error while updating characteristic (ret=0x%x).\n\r", ret);
          switch (ret) {
            case BLE_STATUS_INVALID_HANDLE:
            case BLE_STATUS_INVALID_PARAMETER:
              return BLE_ERROR_INVALID_PARAM;
            default:
              return BLE_STACK_BUSY;
          }
        }

        return BLE_ERROR_NONE;
    } else {
Ejemplo n.º 2
0
ble_error_t MaximGattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
{
    if (connectionHandle != DM_CONN_ID_NONE) {
        uint8_t idx;
        for (idx = 0; idx < cccCnt; idx++) {
            if (characteristic.getValueHandle() == cccHandles[idx]) {
                uint16_t cccValue = AttsCccGet(connectionHandle, idx);
                if (cccValue & ATT_CLIENT_CFG_NOTIFY) {
                    *enabledP = true;
                } else {
                    *enabledP = false;
                }
                return BLE_ERROR_NONE;
            }
        }
    }

    return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
Ejemplo n.º 3
0
ble_error_t nRF5xGattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
{
    return areUpdatesEnabled(connectionHandle, characteristic.getValueHandle(), enabledP);
}