This commit is contained in:
hathach committed 2018-01-22 22:05:30 +07:00
1 parent 5f491c5239
commit c292b39f51
4 files changed
+37 -26

No files matched your search

+1 -1
View File
@@ -172,7 +172,7 @@ const char* dbg_err_str(uint32_t err_id); // TODO move to other place
#define ADALOG_BUFFER(_tag, _buf, _n) \
do {\
if ( _tag ) cprintf("[%-6s] ", _tag);\
if ( _tag ) cprintf("[%-6s]\n", _tag);\
dbgDumpMemory(_buf, 1, _n, true);\
}while(0)
@@ -76,7 +76,9 @@ void HAPCharacteristic::setHapProperties(uint16_t prop)
{
_hap_props = prop;
// HAP always require read and write
uint8_t chrprop = CHR_PROPS_READ | CHR_PROPS_WRITE;
if ((prop & HAP_CHR_PROPS_NOTIFY) || (prop & HAP_CHR_PROPS_NOTIFY_DISCONNECTED)) chrprop |= CHR_PROPS_INDICATE;
setProperties(chrprop);
@@ -271,7 +273,7 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
hap_resp = createHapResponse(hap_req->header.tid, HAP_STATUS_INVALID_INSTANCE_ID);
}else
{
LOG_LV2("HAP", "Recv %s request, TID = %02X, CS_ID = %04X", hap_opcode_str[hap_req->header.opcode], hap_req->header.tid, hap_req->header.instance_id);
LOG_LV2("HAP", "Recv %s request, TID = 0x%02X, CS_ID = 0x%04X", hap_opcode_str[hap_req->header.opcode], hap_req->header.tid, hap_req->header.instance_id);
switch(hap_req->header.opcode)
{
case HAP_OPCODE_CHR_SIGNATURE_READ:
@@ -314,8 +316,8 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_INSUF_RESOURCES;
}
LOG_LV2("HAP", "Response: Control = %02X, TID = %02X, Status = %02X", hap_resp->header.control, hap_resp->header.tid, hap_resp->header.status);
LOG_LV2_BUFFER(NULL, hap_resp, reply.params.write.len);
LOG_LV2("HAP", "Response: Control = 0x%02X, TID = 0x%02X, Status = %d", hap_resp->header.control, hap_resp->header.tid, hap_resp->header.status);
// LOG_LV2_BUFFER(NULL, hap_resp, reply.params.write.len);
err_t err = sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply);
rtos_free(hap_resp);
+18 -18
View File
@@ -48,24 +48,24 @@ enum HAPOpcode_t
enum HAPParamType_t
{
HAP_PARAM_VALUE = 1 ,
HAP_PARAM_ADDITIONAL_AUTHORIZATION_DATA ,
HAP_PARAM_ORIGIN , // local vs remote
HAP_PARAM_CHR_TYPE ,
HAP_PARAM_CHR_ID ,
HAP_PARAM_SVC_TYPE ,
HAP_PARAM_SVC_ID ,
HAP_PARAM_TTL ,
HAP_PARAM_RETURN_RESP ,
HAP_PARAM_HAP_CHR_PROPERTIES_DESC ,
HAP_PARAM_GATT_USR_DESC ,
HAP_PARAM_GATT_FORMAT_DESC ,
HAP_PARAM_GATT_VALID_RANGE ,
HAP_PARAM_HAP_STEP_VALUE_DESC ,
HAP_PARAM_HAP_SVC_PROPERTIES ,
HAP_PARAM_HAP_LINKED_SVC ,
HAP_PARAM_HAP_VALID_VALUES_DESC ,
HAP_PARAM_HAP_VALID_VALUES_RANGE_DESC
HAP_PARAM_VALUE = 1 , // 1
HAP_PARAM_ADDITIONAL_AUTHORIZATION_DATA , // 2
HAP_PARAM_ORIGIN , // 3 local vs remote
HAP_PARAM_CHR_TYPE , // 4
HAP_PARAM_CHR_ID , // 5
HAP_PARAM_SVC_TYPE , // 6
HAP_PARAM_SVC_ID , // 7
HAP_PARAM_TTL , // 8
HAP_PARAM_RETURN_RESP , // 9
HAP_PARAM_HAP_CHR_PROPERTIES_DESC , // 10
HAP_PARAM_GATT_USR_DESC , // 11
HAP_PARAM_GATT_FORMAT_DESC , // 12
HAP_PARAM_GATT_VALID_RANGE , // 13
HAP_PARAM_HAP_STEP_VALUE_DESC , // 14
HAP_PARAM_HAP_SVC_PROPERTIES , // 15
HAP_PARAM_HAP_LINKED_SVC , // 16
HAP_PARAM_HAP_VALID_VALUES_DESC , // 17
HAP_PARAM_HAP_VALID_VALUES_RANGE_DESC // 18
};
enum HAPStatusCode_t
@@ -41,6 +41,8 @@
#include "crypto/crypto.h"
#define DEBUG_HAP_PAIRING 0
/*
The following is a description of SRP-6 and 6a, the latest versions of SRP:
@@ -190,13 +192,14 @@ HAPResponse_t* createSrpResponse(uint8_t tid, uint8_t status, TLV8_t ktlv[], uin
if( srplen == tlv8_encode_n(srpbuf, srplen, ktlv, count) )
{
LOG_LV2_BUFFER("PAIR-SETUP", srpbuf, srplen);
#if DEBUG_HAP_PAIRING
LOG_LV2_BUFFER("M1 Response", srpbuf, srplen);
#endif
TLV8_t tlv = { .type = HAP_PARAM_VALUE, .len = srplen, .value = srpbuf };
hap_resp = createHapResponse(tid, status, &tlv, 1);
}
// LOG_LV2_BUFFER("PAIR-SETUP", hap_resp, hap_resp->body_len + sizeof(HAPResponseHeader_t) + 2);
rtos_free(srpbuf);
return hap_resp;
}
@@ -276,10 +279,16 @@ static HAPResponse_t* pairing_setup_write_cb (HAPCharacteristic* chr, ble_gatts_
TLV8_t tlv_para[] =
{
{ .type = PAIRING_TYPE_STATE , .len = 1 , .value = &mstate },
{ .type = PAIRING_TYPE_PUBLIC_KEY , .len = 384, .value = srp_getB() },
{ .type = PAIRING_TYPE_SALT , .len = 16 , .value = srp_getSalt() },
{ .type = PAIRING_TYPE_PUBLIC_KEY , .len = 384, .value = srp_getB() },
};
#if DEBUG_HAP_PAIRING
LOG_LV2_BUFFER("SRP State" , tlv_para[0].value, tlv_para[0].len);
LOG_LV2_BUFFER("SRP Salt" , tlv_para[1].value, tlv_para[1].len);
LOG_LV2_BUFFER("SRP Pub Key", tlv_para[2].value, tlv_para[2].len);
#endif
hap_resp = createSrpResponse(hap_req->header.tid, HAP_STATUS_SUCCESS, tlv_para, arrcount(tlv_para));
break;
}