change the linker memory for homekit

This commit is contained in:
hathach committed 2017-10-25 22:53:44 +07:00
1 parent ee1d76b2d5
commit 0f17739b2d
11 files changed
+90 -27

No files matched your search

+2 -1
View File
@@ -14,7 +14,8 @@ MEMORY
* - Max ATT MTU is 247
* - Event Len = 3, HVN queue = 3, Write CMD queue =3
*/
RAM (rwx) : ORIGIN = 0x20003000, LENGTH = 0xC000
/* RAM (rwx) : ORIGIN = 0x20003000, LENGTH = 0x20010000 - 0x20003000 */
RAM (rwx) : ORIGIN = 0x20003800, LENGTH = 0x20010000 - 0x20003800
/* Reference configuration
- MTU = 247, hvn = 7, wrcmd = 3 , evt len = 3
+2
View File
@@ -122,6 +122,8 @@ extern "C"
*/
#define VERIFY(...) VERIFY_GETARGS(__VA_ARGS__, VERIFY_2ARGS, VERIFY_1ARGS)(__VA_ARGS__)
// TODO VERIFY with final statement
#ifdef __cplusplus
}
#endif
+3 -1
View File
@@ -102,13 +102,15 @@ bool BLEHomekit::setAdv(BLEAdvertisingData& adv_ref)
.type = 0x06,
.adv_int_len = ail,
.status_flag = 1, // bit0 = HAP Pairing Status Flag (1 not paired)
.dev_id = { 0x0a, 0xbc, 0x12, 0x33, 0x56, 0x98 },
.dev_id = { 0x00},
.category = HAP_CAT_LIGHTBULB,
.gsn = 1,
.config_num = 1,
.compatible_verion = HOMEKIT_PROTOCOL_VERION
};
Bluefruit.Gap.getAddr(data.dev_id);
VERIFY_STATIC( sizeof(data) == 17);
adv.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
+51 -17
View File
@@ -49,10 +49,11 @@ BLEUuid HAPCharacteristic::_g_uuid_cid(HAP_UUID_DSC_CHARACTERISTIC_ID);
HAPCharacteristic::HAPCharacteristic(BLEUuid bleuuid, uint8_t format, uint16_t unit)
: BLECharacteristic(bleuuid)
{
_cid = 0;
_cid = 0;
_hap_props = 0;
_resp_len = 0;
_resp_len = 0;
_tid = 0;
setPresentationFormatDescriptor(format, 0, unit, 1, 0);
}
@@ -131,13 +132,13 @@ HAPResponse_t* HAPCharacteristic::createHapResponse(uint8_t tid, uint8_t status,
hap_resp->header.control.fragment = 0;
hap_resp->header.control.type = HAP_PDU_RESPONSE;
hap_resp->header.tid = tid;
hap_resp->header.status = HAP_STATUS_SUCCESS;
hap_resp->header.status = status;
hap_resp->body_len = (count ? body_len : 0);
/*------------- Serialize Data -------------*/
uint8_t* pdata = hap_resp->body_data;
for(uint8_t i=0; i < arrcount(tlv_para); i++)
for(uint8_t i=0; i < count; i++)
{
memcpy(pdata, &tlv_para[i], 2); // type + len
pdata += 2;
@@ -146,11 +147,17 @@ HAPResponse_t* HAPCharacteristic::createHapResponse(uint8_t tid, uint8_t status,
pdata += tlv_para[i].len;
}
_resp_len = sizeof(HAPResponseHeader_t) + hap_resp->body_len;
return hap_resp;
}
void reverse_uuid128(uint8_t const in[16], uint8_t out[16])
{
for(uint8_t i=0; i<16; i++)
{
out[i] = in[15-i];
}
}
void HAPCharacteristic::_eventHandler(ble_evt_t* event)
{
const uint16_t conn_hdl = event->evt.common_evt.conn_handle;
@@ -184,12 +191,18 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
}
};
if ( (hap_req->header.control.type != HAP_PDU_REQUEST) || (hap_req->header.instance_id != _cid) )
_tid = hap_req->header.tid;
if (hap_req->header.control.type != HAP_PDU_REQUEST)
{
hap_resp = createHapResponse(hap_req->header.tid, HAP_STATUS_INVALID_REQUEST, NULL, 0);
hap_resp = createHapResponse(hap_req->header.tid, HAP_STATUS_UNSUPPORTED_PDU, NULL, 0);
}
else if (hap_req->header.instance_id != _cid)
{
hap_resp = createHapResponse(hap_req->header.tid, HAP_STATUS_INVALID_INSTANCE_ID, NULL, 0);
}else
{
PRINT_INT(hap_req->header.opcode);
LOG_LV2(HAP, "Opcode = %d", hap_req->header.opcode);
switch(hap_req->header.opcode)
{
/* Return <Chr Type, Svc Type, Svc ID, Meta Descriptors>
@@ -221,7 +234,7 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
TLV8_t tlv_para[] =
{
{ .type = HAP_PARAM_CHR_TYPE, .len = 16, .value = uuid._uuid128 },
{ .type = HAP_PARAM_CHR_ID , .len = 2 , .value = &_cid },
// { .type = HAP_PARAM_CHR_ID , .len = 2 , .value = &_cid },
{ .type = HAP_PARAM_SVC_TYPE, .len = 16, .value = _service->uuid._uuid128 },
{ .type = HAP_PARAM_SVC_ID , .len = 2 , .value = &svc_id },
// Descriptors
@@ -234,17 +247,18 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
break;
default:
hap_resp = createHapResponse(hap_req->header.tid, HAP_STATUS_INVALID_REQUEST, NULL, 0);
hap_resp = createHapResponse(hap_req->header.tid, HAP_STATUS_UNSUPPORTED_PDU, NULL, 0);
break;
}
}
if ( hap_resp )
{
reply.params.write.len = _resp_len; // sizeof(HAPResponseHeader_t) + hap_resp->body_len;
reply.params.write.len = _resp_len = sizeof(HAPResponseHeader_t) + hap_resp->body_len;
reply.params.write.p_data = (uint8_t*) hap_resp;
}else
{
_resp_len = 0;
reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_INSUF_RESOURCES;
}
@@ -267,7 +281,7 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
.type = BLE_GATTS_AUTHORIZE_TYPE_READ,
.params = {
.read = {
.gatt_status = BLE_GATT_STATUS_ATTERR_READ_NOT_PERMITTED,
.gatt_status = BLE_GATT_STATUS_SUCCESS,
.update = 0,
.offset = 0,
.len = 0,
@@ -278,12 +292,32 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
if (_resp_len)
{
reply.params.read.gatt_status = BLE_GATT_STATUS_SUCCESS;
_resp_len -= min16(_resp_len, Bluefruit.Gap.getMTU(conn_hdl)-2);
}
VERIFY_STATUS( sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply), );
}else
{
#if 1
reply.params.read.gatt_status = BLE_GATT_STATUS_ATTERR_READ_NOT_PERMITTED;
VERIFY_STATUS( sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply), );
#elif 0
HAPResponse_t* hap_resp = createHapResponse(_tid, HAP_STATUS_INVALID_REQUEST, NULL, 0);
VERIFY_STATUS( sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply), );
reply.params.read.update = 1;
reply.params.read.len = sizeof(HAPResponseHeader_t) + hap_resp->body_len;
reply.params.read.p_data = (uint8_t*) hap_resp;
err_t err = sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply);
rtos_free(hap_resp);
VERIFY_STATUS( err, );
#else
reply.params.read.update = 1;
reply.params.read.len = 0;
reply.params.read.p_data = NULL;
err_t err = sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply);
#endif
}
}
}
break;
@@ -70,6 +70,7 @@ class HAPCharacteristic : public BLECharacteristic
uint16_t _hap_props;
uint16_t _resp_len;
uint8_t _tid;
err_t _addChrIdDescriptor(void);
@@ -39,7 +39,9 @@
#include "HAPLightBulb.h"
HAPLightBulb::HAPLightBulb(void)
: HAPService(HAP_UUID_SVC_LIGHT_BULB), _on(HAP_UUID_CHR_ON, BLE_GATT_CPF_FORMAT_BOOLEAN)
: HAPService(HAP_UUID_SVC_LIGHT_BULB),
_on(HAP_UUID_CHR_ON, BLE_GATT_CPF_FORMAT_BOOLEAN),
_name(HAP_UUID_CHR_NAME, BLE_GATT_CPF_FORMAT_UTF8S)
{
}
@@ -52,5 +54,9 @@ err_t HAPLightBulb::begin(void)
_on.setHapProperties(HAP_CHR_PROPS_SECURE_READ | HAP_CHR_PROPS_SECURE_WRITE | HAP_CHR_PROPS_NOTIFY );
VERIFY_STATUS( _on.begin() );
// Name char
_name.setHapProperties(HAP_CHR_PROPS_SECURE_READ);
VERIFY_STATUS( _name.begin() );
return ERROR_NONE;
}
@@ -48,6 +48,7 @@ class HAPLightBulb : public HAPService
private:
HAPCharacteristic _on;
HAPCharacteristic _name;
};
@@ -58,7 +58,7 @@ err_t HAPPairing::begin(void)
VERIFY_STATUS( _setup.begin() );
_verify.setHapProperties(HAP_CHR_PROPS_READ | HAP_CHR_PROPS_WRITE);
_verify.setMaxLen(100);
_verify.setMaxLen(BLE_GATTS_VAR_ATTR_LEN_MAX);
VERIFY_STATUS( _verify.begin() );
_features.setHapProperties(HAP_CHR_PROPS_READ);
+15 -1
View File
@@ -214,12 +214,26 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
}
break;
case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST:
// Let Softdevice decide the data length
// ble_gap_data_length_params_t* param = &evt->evt.gap_evt.params.data_length_update_request.peer_params
VERIFY_STATUS( sd_ble_gap_data_length_update(conn_handle, NULL, NULL), );
break;
case BLE_GAP_EVT_DATA_LENGTH_UPDATE:
{
ble_gap_data_length_params_t* datalen = &evt->evt.gap_evt.params.data_length_update.effective_params;
LOG_LV1(GAP, "Data Length is (tx, rx) octets = (%d, %d), (tx, rx) time = (%d, %d) us",
datalen->max_tx_octets, datalen->max_rx_octets, datalen->max_tx_time_us, datalen->max_rx_time_us);
}
break;
case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
{
peer->att_mtu = minof(evt->evt.gatts_evt.params.exchange_mtu_request.client_rx_mtu, BLEGATT_ATT_MTU_MAX);
VERIFY_STATUS( sd_ble_gatts_exchange_mtu_reply(conn_handle, peer->att_mtu), );
LOG_LV1(BLE, "ATT MTU is changed to %d", peer->att_mtu);
LOG_LV1(GAP, "ATT MTU is changed to %d", peer->att_mtu);
}
break;
+5 -3
View File
@@ -223,8 +223,8 @@ err_t AdafruitBluefruit::begin(bool prph_enable, bool central_enable)
// Event Length + HVN queue + WRITE CMD queue setting affecting bandwidth
varclr(&blecfg);
blecfg.conn_cfg.conn_cfg_tag = BLE_CONN_CFG_HIGH_BANDWIDTH;
blecfg.conn_cfg.params.gap_conn_cfg.conn_count = 1; // BLE_GAP_CONN_COUNT_DEFAULT
blecfg.conn_cfg.params.gap_conn_cfg.event_length = BLEGAP_EVENT_LENGTH; // BLE_GAP_EVENT_LENGTH_DEFAULT
blecfg.conn_cfg.params.gap_conn_cfg.conn_count = 1;
blecfg.conn_cfg.params.gap_conn_cfg.event_length = BLEGAP_EVENT_LENGTH;
VERIFY_STATUS ( sd_ble_cfg_set(BLE_CONN_CFG_GAP, &blecfg, ram_start) );
// HVN queue size
@@ -276,7 +276,7 @@ err_t AdafruitBluefruit::begin(bool prph_enable, bool central_enable)
VERIFY_STATUS( sd_ble_gap_tx_power_set( CFG_BLE_TX_POWER_LEVEL ) );
/*------------- DFU OTA as built-in service -------------*/
_dfu_svc.begin();
// _dfu_svc.begin();
if (_central_enabled) Central.begin(); // Init Central
@@ -702,6 +702,8 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
if (_disconnect_cb) ada_callback(NULL, _disconnect_cb, _conn_hdl, evt->evt.gap_evt.params.disconnected.reason);
LOG_LV2(GAP, "Disconnect Reason 0x%02X", evt->evt.gap_evt.params.disconnected.reason);
_conn_hdl = BLE_CONN_HANDLE_INVALID;
_bonded = false;
break;
+2 -2
View File
@@ -52,9 +52,9 @@
* - BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT = 1
* - BLEGATT_ATT_MTU_MAX from 23 (default) to 247
*/
#define BLE_GATTS_ATTR_TABLE_SIZE 0x800 //0x0B00 default is 0x580
#define BLE_GATTS_ATTR_TABLE_SIZE 0xB00 //0x0B00 default is 0x580
#define BLE_VENDOR_UUID_MAX 20
#define BLEGAP_EVENT_LENGTH BLE_GAP_EVENT_LENGTH_DEFAULT
#define BLEGAP_EVENT_LENGTH 6
#define BLEGAP_HVN_TX_QUEUE_SIZE 3
#define BLEGAP_WRITECMD_TX_QUEUE_SIZE 3
#define BLEGATT_ATT_MTU_MAX 247