bool ieee802154_decipher_data_frame(struct net_if *iface, struct net_pkt *pkt, struct ieee802154_mpdu *mpdu) { struct ieee802154_context *ctx = net_if_l2_data(iface); u8_t level; if (!mpdu->mhr.fs->fc.security_enabled) { return true; } /* Section 7.2.3 (i) talks about "security level policy" conformance * but such policy does not seem to be detailed. So let's assume both * ends should have same security level. */ if (mpdu->mhr.aux_sec->control.security_level != ctx->sec_ctx.level) { return false; } /* ToDo: handle src short address * This will require to look up in nbr cache with short addr * in order to get the extended address related to it */ if (!ieee802154_decrypt_auth(&ctx->sec_ctx, net_pkt_ll(pkt), net_pkt_ll_reserve(pkt), net_pkt_get_len(pkt), net_pkt_ll_src(pkt)->addr, sys_le32_to_cpu( mpdu->mhr.aux_sec->frame_counter))) { NET_ERR("Could not decipher the frame"); return false; } level = ctx->sec_ctx.level; if (level >= IEEE802154_SECURITY_LEVEL_ENC) { level -= 4; } /* We remove tag size from frag's length, it is now useless */ pkt->frags->len -= level_2_tag_size[level]; return true; }
static void passkey_entry(const uint8_t *data, uint16_t len) { const struct gap_passkey_entry_cmd *cmd = (void *) data; struct bt_conn *conn; uint8_t status; conn = bt_conn_lookup_addr_le((bt_addr_le_t *) data); if (!conn) { status = BTP_STATUS_FAILED; goto rsp; } bt_conn_auth_passkey_entry(conn, sys_le32_to_cpu(cmd->passkey)); bt_conn_unref(conn); status = BTP_STATUS_SUCCESS; rsp: tester_rsp(BTP_SERVICE_ID_GAP, GAP_PASSKEY_ENTRY, CONTROLLER_INDEX, status); }
static ssize_t write_ctrl_point(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, uint16_t len, uint16_t offset) { const struct write_sc_ctrl_point_req *req = buf; uint8_t status; int i; if (!ctrl_point_configured) { return BT_GATT_ERR(CSC_ERR_CCC_CONFIG); } if (!len) { return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); } switch (req->op) { case SC_CP_OP_SET_CWR: if (len != sizeof(req->op) + sizeof(req->cwr)) { status = SC_CP_RSP_INVAL_PARAM; break; } cwr = sys_le32_to_cpu(req->cwr); status = SC_CP_RSP_SUCCESS; break; case SC_CP_OP_UPDATE_LOC: if (len != sizeof(req->op) + sizeof(req->location)) { status = SC_CP_RSP_INVAL_PARAM; break; } /* Break if the requested location is the same as current one */ if (req->location == sensor_location) { status = SC_CP_RSP_SUCCESS; break; } /* Pre-set status */ status = SC_CP_RSP_INVAL_PARAM; /* Check if requested location is supported */ for (i = 0; i < ARRAY_SIZE(supported_locations); i++) { if (supported_locations[i] == req->location) { sensor_location = req->location; status = SC_CP_RSP_SUCCESS; break; } } break; case SC_CP_OP_REQ_SUPP_LOC: if (len != sizeof(req->op)) { status = SC_CP_RSP_INVAL_PARAM; break; } /* Indicate supported locations and return */ ctrl_point_ind(conn, req->op, SC_CP_RSP_SUCCESS, &supported_locations, sizeof(supported_locations)); return len; default: status = SC_CP_RSP_OP_NOT_SUPP; } ctrl_point_ind(conn, req->op, status, NULL, 0); return len; }