Bluetooth: controller: refactored llcp_req/ack test to helper function

Moved test of llcp_req/ack to separate helper function in ull_conn.c

Signed-off-by: Alexander Svensen <alsv@nordicsemi.no>
This commit is contained in:
Alexander Svensen 2019-02-06 15:53:16 +01:00 committed by Carles Cufí
commit 8d86773d6b
4 changed files with 46 additions and 49 deletions

View file

@ -168,6 +168,22 @@ struct ll_conn *ll_connected_get(u16_t handle)
return conn;
}
u8_t ull_conn_allowed_check(void *conn)
{
struct ll_conn * const conn_hdr = conn;
if (conn_hdr->llcp_req != conn_hdr->llcp_ack) {
return BT_HCI_ERR_CMD_DISALLOWED;
}
conn_hdr->llcp_req++;
if (((conn_hdr->llcp_req - conn_hdr->llcp_ack) & 0x03) != 1) {
conn_hdr->llcp_req--;
return BT_HCI_ERR_CMD_DISALLOWED;
}
return 0;
}
void *ll_tx_mem_acquire(void)
{
return mem_acquire(&mem_conn_tx.free);
@ -206,6 +222,7 @@ u8_t ll_conn_update(u16_t handle, u8_t cmd, u8_t status, u16_t interval_min,
u16_t interval_max, u16_t latency, u16_t timeout)
{
struct ll_conn *conn;
u8_t ret;
conn = ll_connected_get(handle);
if (!conn) {
@ -230,14 +247,10 @@ u8_t ll_conn_update(u16_t handle, u8_t cmd, u8_t status, u16_t interval_min,
}
if (!cmd) {
if (conn->llcp_req != conn->llcp_ack) {
return BT_HCI_ERR_CMD_DISALLOWED;
}
conn->llcp_req++;
if (((conn->llcp_req - conn->llcp_ack) & 0x03) != 1) {
conn->llcp_req--;
return BT_HCI_ERR_CMD_DISALLOWED;
ret = ull_conn_allowed_check(conn);
if (ret) {
return ret;
}
conn->llcp.conn_upd.win_size = 1;
@ -331,16 +344,16 @@ u8_t ll_terminate_ind_send(u16_t handle, u8_t reason)
u8_t ll_feature_req_send(u16_t handle)
{
struct ll_conn *conn;
u8_t ret;
conn = ll_connected_get(handle);
if (!conn || (conn->llcp_req != conn->llcp_ack)) {
if (!conn) {
return BT_HCI_ERR_CMD_DISALLOWED;
}
conn->llcp_req++;
if (((conn->llcp_req - conn->llcp_ack) & 0x03) != 1) {
conn->llcp_req--;
return BT_HCI_ERR_CMD_DISALLOWED;
ret = ull_conn_allowed_check(conn);
if (ret) {
return ret;
}
conn->llcp_type = LLCP_FEATURE_EXCHANGE;
@ -352,16 +365,16 @@ u8_t ll_feature_req_send(u16_t handle)
u8_t ll_version_ind_send(u16_t handle)
{
struct ll_conn *conn;
u8_t ret;
conn = ll_connected_get(handle);
if (!conn || (conn->llcp_req != conn->llcp_ack)) {
if (!conn) {
return BT_HCI_ERR_CMD_DISALLOWED;
}
conn->llcp_req++;
if (((conn->llcp_req - conn->llcp_ack) & 0x03) != 1) {
conn->llcp_req--;
return BT_HCI_ERR_CMD_DISALLOWED;
ret = ull_conn_allowed_check(conn);
if (ret) {
return ret;
}
conn->llcp_type = LLCP_VERSION_EXCHANGE;