Skip to content

Commit

Permalink
zephyr: hogp: prevent changing protocol mode during CCC write
Browse files Browse the repository at this point in the history
  • Loading branch information
benedekkupper committed Feb 11, 2024
1 parent c708969 commit ea4a631
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions c2usb/port/zephyr/bluetooth/hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,20 @@ ssize_t service::ccc_cfg_write(::bt_conn* conn, const gatt::attribute* attr, gat
}
auto* this_ = reinterpret_cast<service*>(attr->user_data);

if (flags != gatt::ccc_flags::NONE)
// clearing the flag has no conditions nor consequences
if (flags == gatt::ccc_flags::NONE)
{
return this_->start_app(conn, protocol) ? sizeof(flags)
: BT_GATT_ERR(HOGP_ALREADY_CONNECTED_ERROR);
return sizeof(flags);
}
return sizeof(flags);

// prevent changing protocol mode
if ((protocol == protocol::BOOT) && (this_->get_protocol() != protocol))
{
return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED);
}

return this_->start_app(conn, protocol) ? sizeof(flags)
: BT_GATT_ERR(HOGP_ALREADY_CONNECTED_ERROR);
}

gatt::attribute::builder service::add_input_report(gatt::attribute::builder attr_tail,
Expand Down

0 comments on commit ea4a631

Please sign in to comment.