本文整理汇总了C++中bt_flip_addr函数的典型用法代码示例。如果您正苦于以下问题:C++ bt_flip_addr函数的具体用法?C++ bt_flip_addr怎么用?C++ bt_flip_addr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bt_flip_addr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: hci_send_cmd_packet
int hci_send_cmd_packet(uint8_t *packet, int size){
bd_addr_t addr;
hci_connection_t * conn;
// house-keeping
// create_connection?
if (IS_COMMAND(packet, hci_create_connection)){
bt_flip_addr(addr, &packet[3]);
log_info("Create_connection to %s\n", bd_addr_to_str(addr));
conn = connection_for_address(addr);
if (conn) {
// if connection exists
if (conn->state == OPEN) {
// and OPEN, emit connection complete command
hci_emit_connection_complete(conn, 0);
}
// otherwise, just ignore as it is already in the open process
return 0; // don't sent packet to controller
}
// create connection struct and register, state = SENT_CREATE_CONNECTION
conn = create_connection_for_addr(addr);
if (!conn){
// notify client that alloc failed
hci_emit_connection_complete(conn, BTSTACK_MEMORY_ALLOC_FAILED);
return 0; // don't sent packet to controller
}
conn->state = SENT_CREATE_CONNECTION;
}
if (IS_COMMAND(packet, hci_link_key_request_reply)){
hci_add_connection_flags_for_flipped_bd_addr(&packet[3], SENT_LINK_KEY_REPLY);
}
if (IS_COMMAND(packet, hci_link_key_request_negative_reply)){
hci_add_connection_flags_for_flipped_bd_addr(&packet[3], SENT_LINK_KEY_NEGATIVE_REQUEST);
}
if (IS_COMMAND(packet, hci_pin_code_request_reply)){
hci_add_connection_flags_for_flipped_bd_addr(&packet[3], SENT_PIN_CODE_REPLY);
}
if (IS_COMMAND(packet, hci_pin_code_request_negative_reply)){
hci_add_connection_flags_for_flipped_bd_addr(&packet[3], SENT_PIN_CODE_NEGATIVE_REPLY);
}
if (IS_COMMAND(packet, hci_delete_stored_link_key)){
if (hci_stack.remote_device_db){
bt_flip_addr(addr, &packet[3]);
hci_stack.remote_device_db->delete_link_key(&addr);
}
}
hci_stack.num_cmd_packets--;
return hci_stack.hci_transport->send_packet(HCI_COMMAND_DATA_PACKET, packet, size);
}
开发者ID:ajsb85,项目名称:ioio,代码行数:53,代码来源:hci.c
示例2: bt_control_bcm_set_bd_addr_cmd
// @note: bd addr has to be set after sending init script (it might just get re-set)
static int bt_control_bcm_set_bd_addr_cmd(void * config, bd_addr_t addr, uint8_t *hci_cmd_buffer){
hci_cmd_buffer[0] = 0x01;
hci_cmd_buffer[1] = 0xfc;
hci_cmd_buffer[2] = 0x06;
bt_flip_addr(&hci_cmd_buffer[3], addr);
return 0;
}
开发者ID:Mechelix,项目名称:btstack,代码行数:8,代码来源:bt_control_bcm.c
示例3: hci_connected
int hci_connected(uint8_t *packet, uint16_t size)
{
bd_addr_t event_addr;
// inform about new l2cap connection
bt_flip_addr(event_addr, &packet[3]);
uint16_t psm = READ_BT_16(packet, 11);
bt_accessor(0)->connflags.source_cid = READ_BT_16(packet, 13);
bt_accessor(0)->connflags.con_handle = READ_BT_16(packet, 9);
if (packet[2] == 0) {
printf("Channel successfully opened: ");
print_bd_addr(event_addr);
printf(", handle 0x%02x, psm 0x%02x, source cid 0x%02x, dest cid 0x%02x\n",
bt_accessor(0)->connflags.con_handle, psm, bt_accessor(0)->connflags.source_cid, READ_BT_16(packet, 15));
// send SABM command on dlci 0
printf("Sending SABM #0\n");
_bt_rfcomm_send_sabm(bt_accessor(0)->connflags.source_cid, 1, 0);
} else {
printf("L2CAP connection to device ");
print_bd_addr(event_addr);
printf(" failed. status code %u\n", packet[2]);
return (1);
}
return (0);
}
开发者ID:darkfall,项目名称:ArduinoBot,代码行数:26,代码来源:BTLayer.c
示例4: hci_inquiry_result
int hci_inquiry_result(uint8_t *packet, uint16_t size)
{
int numResponses;
bd_addr_t addr;
t_device res;
int i;
numResponses = packet[2];
for (i=0; i< numResponses && btscan_count_node(bt_accessor(0)->root) < MAX_DEVICES;i++)
{
bt_flip_addr(addr, &packet[3+i*6]);
if (btscan_find_node(bt_accessor(0)->root, addr))
continue;
memset(&res, 0, sizeof(res));
memcpy(res.address, addr, 6);
res.pageScanRepetitionMode = packet [3 + numResponses*(6) + i*1];
res.classOfDevice = READ_BT_24(packet, 3 + numResponses*(packet[0] == HCI_EVENT_INQUIRY_RESULT_WITH_RSSI ?
(6+1+1) :
(6+1+1+1))+ i*3);
res.clockOffset = READ_BT_16(packet, 3 + numResponses*(packet[0] == HCI_EVENT_INQUIRY_RESULT_WITH_RSSI ?
(6+1+1+3) :
(6+1+1+1+3)) + i*2) & 0x7fff;
res.rssi = (packet[0] == HCI_EVENT_INQUIRY_RESULT_WITH_RSSI ? packet [3 + numResponses*(6+1+1+3+2) + i*1] : 0);
res.state = 1;
printf("Device found: ");
print_bd_addr(addr);
printf(" with COD: 0x%06x, pageScan %u, clock offset 0x%04x\n", res.classOfDevice, res.pageScanRepetitionMode, res.clockOffset);
bt_accessor(0)->root = btscan_add_node(bt_accessor(0)->root, &res);
}
return (0);
}
开发者ID:darkfall,项目名称:ArduinoBot,代码行数:31,代码来源:BTLayer.c
示例5: handle_hci_event
static void handle_hci_event(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
if (packet_type != HCI_EVENT_PACKET) return;
bd_addr_t address;
uint8_t event = packet[0];
switch (event) {
case BTSTACK_EVENT_STATE:
if (packet[2] != HCI_STATE_WORKING) break;
le_central_set_scan_parameters(0,0x0030, 0x0030);
le_central_start_scan();
break;
case GAP_LE_ADVERTISING_REPORT:{
advertisement_received = 1;
memcpy(advertisement_packet, packet, size);
bt_flip_addr(address, &packet[4]);
le_central_connect(address, (bd_addr_type_t)packet[3]);
break;
}
case HCI_EVENT_LE_META:
// wait for connection complete
if (packet[2] != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break;
connected = 1;
break;
case HCI_EVENT_DISCONNECTION_COMPLETE:
exit(0);
break;
default:
break;
}
}
开发者ID:Mechelix,项目名称:btstack,代码行数:32,代码来源:le_central.c
示例6: handle_hci_event
static void handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
if (packet_type != HCI_EVENT_PACKET) return;
switch (packet[0]) {
case BTSTACK_EVENT_STATE:
// BTstack activated, get started
if (packet[2] == HCI_STATE_WORKING) {
printf("BTstack activated, start scaning!\n");
le_central_set_scan_parameters(0,0x0030, 0x0030);
le_central_start_scan();
}
break;
case GAP_LE_ADVERTISING_REPORT:{
int pos = 2;
uint8_t event_type = packet[pos++];
uint8_t address_type = packet[pos++];
bd_addr_t address;
bt_flip_addr(address, &packet[pos]);
pos += 6;
uint8_t rssi = packet[pos++];
uint8_t length = packet[pos++];
uint8_t * data = &packet[pos];
printf("Advertisement event: evt-type %u, addr-type %u, addr %s, rssi %u, data[%u] ", event_type,
address_type, bd_addr_to_str(address), rssi, length);
printf_hexdump(data, length);
dump_advertisement_data(data, length);
break;
}
default:
break;
}
}
开发者ID:Mechelix,项目名称:btstack,代码行数:33,代码来源:gap_le_advertisements.c
示例7: hci_add_connection_flags_for_flipped_bd_addr
/**
* add authentication flags and reset timer
*/
static void hci_add_connection_flags_for_flipped_bd_addr(uint8_t *bd_addr, hci_authentication_flags_t flags){
bd_addr_t addr;
bt_flip_addr(addr, *(bd_addr_t *) bd_addr);
hci_connection_t * conn = connection_for_address(addr);
if (conn) {
conn->authentication_flags |= flags;
hci_connection_timestamp(conn);
}
}
开发者ID:ajsb85,项目名称:ioio,代码行数:12,代码来源:hci.c
示例8: hci_link_key_request
int hci_link_key_request(uint8_t *packet, uint16_t size)
{
bd_addr_t event_addr;
// link key request
bt_flip_addr(event_addr, &packet[2]);
bt_send_cmd(&hci_link_key_request_negative_reply, &event_addr);
return (0);
}
开发者ID:darkfall,项目名称:ArduinoBot,代码行数:9,代码来源:BTLayer.c
示例9: hci_emit_remote_name_cached
void hci_emit_remote_name_cached(bd_addr_t *addr, device_name_t *name){
uint8_t event[2+1+6+248];
event[0] = BTSTACK_EVENT_REMOTE_NAME_CACHED;
event[1] = sizeof(event) - 2;
event[2] = 0; // just to be compatible with HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE
bt_flip_addr(&event[3], *addr);
memcpy(&event[9], name, 248);
hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event));
hci_stack.packet_handler(HCI_EVENT_PACKET, event, sizeof(event));
}
开发者ID:ajsb85,项目名称:ioio,代码行数:10,代码来源:hci.c
示例10: hci_pin_code_request
int hci_pin_code_request(uint8_t *packet, uint16_t size)
{
bd_addr_t event_addr;
// inform about pin code request
bt_flip_addr(event_addr, &packet[2]);
bt_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, bt_accessor(0)->pin);
printf("Please enter PIN %s on remote device\n", bt_accessor(0)->pin);
return (0);
}
开发者ID:darkfall,项目名称:ArduinoBot,代码行数:10,代码来源:BTLayer.c
示例11: l2cap_emit_connection_request
void l2cap_emit_connection_request(l2cap_channel_t *channel) {
uint8_t event[16];
event[0] = L2CAP_EVENT_INCOMING_CONNECTION;
event[1] = sizeof(event) - 2;
bt_flip_addr(&event[2], channel->address);
bt_store_16(event, 8, channel->handle);
bt_store_16(event, 10, channel->psm);
bt_store_16(event, 12, channel->local_cid);
bt_store_16(event, 14, channel->remote_cid);
hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
l2cap_dispatch(channel, HCI_EVENT_PACKET, event, sizeof(event));
}
开发者ID:Simu3,项目名称:RobotLog,代码行数:12,代码来源:l2cap.c
示例12: hci_emit_connection_complete
void hci_emit_connection_complete(hci_connection_t *conn, uint8_t status){
uint8_t event[13];
event[0] = HCI_EVENT_CONNECTION_COMPLETE;
event[1] = sizeof(event) - 2;
event[2] = status;
bt_store_16(event, 3, conn->con_handle);
bt_flip_addr(&event[5], conn->address);
event[11] = 1; // ACL connection
event[12] = 0; // encryption disabled
hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
hci_stack.packet_handler(HCI_EVENT_PACKET, event, sizeof(event));
}
开发者ID:ajsb85,项目名称:ioio,代码行数:12,代码来源:hci.c
示例13: packet_handler
static void packet_handler(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
// printf("packet_handler type %u, packet[0] %x\n", packet_type, packet[0]);
if (packet_type == RFCOMM_DATA_PACKET){
hfp_service_level_connection_state++;
if (rfcomm_can_send_packet_now(rfcomm_cid)) send_packet();
return;
}
if (packet_type != HCI_EVENT_PACKET) return;
uint8_t event = packet[0];
bd_addr_t event_addr;
switch (event) {
case BTSTACK_EVENT_STATE:
// bt stack activated, get started
if (packet[2] == HCI_STATE_WORKING){
printf("Start SDP RFCOMM Query for UUID 0x%02x\n", SDP_Handsfree);
// sdp_query_rfcomm_channel_and_name_for_uuid(remote, SDP_Handsfree);
}
break;
case HCI_EVENT_PIN_CODE_REQUEST:
// inform about pin code request
printf("Pin code request - using '0000'\n\r");
bt_flip_addr(event_addr, &packet[2]);
hci_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, "0000");
break;
case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
printf("RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE packet_handler type %u, packet[0] %x\n", packet_type, packet[0]);
// data: event(8), len(8), status (8), address (48), handle(16), server channel(8), rfcomm_cid(16), max frame size(16)
if (packet[2]) {
printf("RFCOMM channel open failed, status %u\n", packet[2]);
} else {
// data: event(8), len(8), status (8), address (48), handle (16), server channel(8), rfcomm_cid(16), max frame size(16)
rfcomm_cid = READ_BT_16(packet, 12);
mtu = READ_BT_16(packet, 14);
printf("RFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n", rfcomm_cid, mtu);
break;
}
break;
case DAEMON_EVENT_HCI_PACKET_SENT:
case RFCOMM_EVENT_CREDITS:
if (!rfcomm_cid) break;
if (rfcomm_can_send_packet_now(rfcomm_cid)) send_packet();
break;
default:
break;
}
}
开发者ID:Mechelix,项目名称:btstack,代码行数:49,代码来源:hfp_test.c
示例14: l2cap_emit_channel_opened
void l2cap_emit_channel_opened(l2cap_channel_t *channel, uint8_t status) {
uint8_t event[21];
event[0] = L2CAP_EVENT_CHANNEL_OPENED;
event[1] = sizeof(event) - 2;
event[2] = status;
bt_flip_addr(&event[3], channel->address);
bt_store_16(event, 9, channel->handle);
bt_store_16(event, 11, channel->psm);
bt_store_16(event, 13, channel->local_cid);
bt_store_16(event, 15, channel->remote_cid);
bt_store_16(event, 17, channel->local_mtu);
bt_store_16(event, 19, channel->remote_mtu);
hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
l2cap_dispatch(channel, HCI_EVENT_PACKET, event, sizeof(event));
}
开发者ID:Simu3,项目名称:RobotLog,代码行数:15,代码来源:l2cap.c
示例15: hci_name_request
int hci_name_request(uint8_t *packet, uint16_t size)
{
bd_addr_t addr;
t_device *t;
bt_flip_addr(addr, &packet[3]);
if ((t = btscan_find_node(bt_accessor(0)->root, addr)))
if (packet[2] == 0 && t->name[0] == 0)
{
printf("Name: '%s'\n", &packet[9]);
memcpy(t->name, &packet[9], (strlen((char *)(&packet[9])) < 254 ? strlen((char *)(&packet[9])) : 253));
t->state = 3;
}
return (0);
}
开发者ID:darkfall,项目名称:ArduinoBot,代码行数:15,代码来源:BTLayer.c
示例16: app_packet_handler
// enable LE, setup ADV data
static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
if (packet_type != HCI_EVENT_PACKET) return;
bd_addr_t addr;
uint8_t adv_data[] = { 02, 01, 05, 03, 02, 0xf0, 0xff };
switch (packet[0]) {
case BTSTACK_EVENT_STATE:
// bt stack activated, get started - set local name
if (packet[2] == HCI_STATE_WORKING) {
printf("Working!\n");
hci_send_cmd(&hci_le_set_advertising_data, sizeof(adv_data), adv_data);
}
break;
case BTSTACK_EVENT_NR_CONNECTIONS_CHANGED:
if (packet[2]) {
printf("CONNECTED");
} else {
printf("DISCONNECTED");
}
break;
case HCI_EVENT_DISCONNECTION_COMPLETE:
// restart advertising
hci_send_cmd(&hci_le_set_advertise_enable, 1);
break;
case HCI_EVENT_COMMAND_COMPLETE:
if (COMMAND_COMPLETE_EVENT(packet, hci_read_bd_addr)){
bt_flip_addr(addr, &packet[6]);
printf("BD ADDR: %s\n", bd_addr_to_str(addr));
break;
}
if (COMMAND_COMPLETE_EVENT(packet, hci_le_set_advertising_data)){
hci_send_cmd(&hci_le_set_scan_response_data, 10, adv_data);
break;
}
if (COMMAND_COMPLETE_EVENT(packet, hci_le_set_scan_response_data)){
hci_send_cmd(&hci_le_set_advertise_enable, 1);
break;
}
default:
break;
}
}
开发者ID:JochenDing,项目名称:btstack,代码行数:47,代码来源:ble_server.c
示例17: packet_handler
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
bd_addr_t event_addr;
uint16_t psm;
if (packet_type != HCI_EVENT_PACKET) return;
switch (packet[0]) {
case BTSTACK_EVENT_STATE:
// bt stack activated, get started
if (packet[2] == HCI_STATE_WORKING){
printf("BTstack L2CAP Test Ready\n");
show_usage();
}
break;
case L2CAP_EVENT_CHANNEL_OPENED:
// inform about new l2cap connection
bt_flip_addr(event_addr, &packet[3]);
psm = READ_BT_16(packet, 11);
local_cid = READ_BT_16(packet, 13);
handle = READ_BT_16(packet, 9);
if (packet[2] == 0) {
printf("Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
bd_addr_to_str(event_addr), handle, psm, local_cid, READ_BT_16(packet, 15));
} else {
printf("L2CAP connection to device %s failed. status code %u\n", bd_addr_to_str(event_addr), packet[2]);
}
break;
case L2CAP_EVENT_INCOMING_CONNECTION: {
uint16_t l2cap_cid = READ_BT_16(packet, 12);
printf("L2CAP Accepting incoming connection request\n");
l2cap_accept_connection_internal(l2cap_cid);
break;
}
default:
break;
}
}
开发者ID:abrasive,项目名称:btstack,代码行数:40,代码来源:l2cap_test.c
示例18: packet_handler
static void packet_handler (void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
bd_addr_t event_addr;
uint8_t rfcomm_channel_nr;
uint16_t mtu;
int i;
switch (packet_type) {
case HCI_EVENT_PACKET:
switch (packet[0]) {
case BTSTACK_EVENT_STATE:
// bt stack activated, get started - set local name
if (packet[2] == HCI_STATE_WORKING) {
hci_send_cmd(&hci_write_local_name, "BTstack SPP Counter");
}
break;
case HCI_EVENT_COMMAND_COMPLETE:
if (COMMAND_COMPLETE_EVENT(packet, hci_read_bd_addr)){
bt_flip_addr(event_addr, &packet[6]);
printf("BD-ADDR: %s\n", bd_addr_to_str(event_addr));
break;
}
break;
case HCI_EVENT_PIN_CODE_REQUEST:
// inform about pin code request
printf("Pin code request - using '0000'\n");
bt_flip_addr(event_addr, &packet[2]);
hci_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, "0000");
break;
case HCI_EVENT_USER_CONFIRMATION_REQUEST:
// inform about user confirmation request
printf("SSP User Confirmation Request with numeric value '%06u'\n", READ_BT_32(packet, 8));
printf("SSP User Confirmation Auto accept\n");
break;
case RFCOMM_EVENT_INCOMING_CONNECTION:
// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
bt_flip_addr(event_addr, &packet[2]);
rfcomm_channel_nr = packet[8];
rfcomm_channel_id = READ_BT_16(packet, 9);
printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(event_addr));
rfcomm_accept_connection_internal(rfcomm_channel_id);
break;
case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
// data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
if (packet[2]) {
printf("RFCOMM channel open failed, status %u\n", packet[2]);
} else {
rfcomm_channel_id = READ_BT_16(packet, 12);
mtu = READ_BT_16(packet, 14);
printf("RFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n", rfcomm_channel_id, mtu);
}
break;
case RFCOMM_EVENT_CHANNEL_CLOSED:
printf("RFCOMM channel closed\n");
rfcomm_channel_id = 0;
break;
default:
break;
}
break;
case RFCOMM_DATA_PACKET:
printf("RCV: '");
for (i=0;i<size;i++){
putchar(packet[i]);
}
printf("'\n");
break;
default:
break;
}
}
开发者ID:BertoDiaz,项目名称:btstack,代码行数:81,代码来源:spp_counter.c
示例19: att_read_callback
// ATT Client Read Callback for Dynamic Data
// - if buffer == NULL, don't copy data, just return size of value
// - if buffer != NULL, copy data and return number bytes copied
// @param offset defines start of attribute value
static uint16_t att_read_callback(uint16_t con_handle, uint16_t attribute_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
printf("READ Callback, handle %04x, offset %u, buffer size %u\n", handle, offset, buffer_size);
uint16_t att_value_len;
uint16_t uuid16 = att_uuid_for_handle(handle);
switch (uuid16){
case 0x2902:
if (buffer) {
buffer[0] = client_configuration;
}
return 1;
case 0x2a00:
att_value_len = strlen(gap_device_name);
if (buffer) {
memcpy(buffer, gap_device_name, att_value_len);
}
return att_value_len;
case 0x2a01:
if (buffer){
bt_store_16(buffer, 0, gap_appearance);
}
return 2;
case 0x2a02:
if (buffer){
buffer[0] = gap_privacy;
}
return 1;
case 0x2A03:
if (buffer) {
bt_flip_addr(buffer, gap_reconnection_address);
}
return 6;
// handle device name
// handle appearance
default:
break;
}
// find attribute
int index = att_attribute_for_handle(handle);
uint8_t * att_value;
if (index < 0){
// not written before
if (att_default_value_long){
att_value = (uint8_t*) default_value_long;
att_value_len = strlen(default_value_long);
} else {
att_value = (uint8_t*) default_value_short;
att_value_len = strlen(default_value_short);
}
} else {
att_value = att_attributes[index].value;
att_value_len = att_attributes[index].len;
}
printf("Attribute len %u, data: ", att_value_len);
printf_hexdump(att_value, att_value_len);
// assert offset <= att_value_len
if (offset > att_value_len) {
return 0;
}
uint16_t bytes_to_copy = att_value_len - offset;
if (!buffer) return bytes_to_copy;
if (bytes_to_copy > buffer_size){
bytes_to_copy = buffer_size;
}
memcpy(buffer, &att_value[offset], bytes_to_copy);
return bytes_to_copy;
}
开发者ID:abrasive,项目名称:btstack,代码行数:75,代码来源:ble_peripheral.c
示例20: event_handler
static void event_handler(uint8_t *packet, int size){
bd_addr_t addr;
uint8_t link_type;
hci_con_handle_t handle;
hci_connection_t * conn;
int i;
switch (packet[0]) {
case HCI_EVENT_COMMAND_COMPLETE:
// get num cmd packets
// log_info("HCI_EVENT_COMMAND_COMPLETE cmds old %u - new %u\n", hci_stack.num_cmd_packets, packet[2]);
hci_stack.num_cmd_packets = packet[2];
if (COMMAND_COMPLETE_EVENT(packet, hci_read_buffer_size)){
// from offset 5
// status
// "The HC_ACL_Data_Packet_Length return parameter will be used to determine the size of the L2CAP segments contained in ACL Data Packets"
hci_stack.acl_data_packet_length = READ_BT_16(packet, 6);
// ignore: SCO data packet len (8)
hci_stack.total_num_acl_packets = packet[9];
// ignore: total num SCO packets
if (hci_stack.state == HCI_STATE_INITIALIZING){
// determine usable ACL payload size
if (HCI_ACL_PAYLOAD_SIZE < hci_stack.acl_data_packet_length){
hci_stack.acl_data_packet_length = HCI_ACL_PAYLOAD_SIZE;
}
// determine usable ACL packet types
hci_stack.packet_types = hci_acl_packet_types_for_buffer_size(hci_stack.acl_data_packet_length);
log_error("hci_read_buffer_size: used size %u, count %u, packet types %04x\n",
hci_stack.acl_data_packet_length, hci_stack.total_num_acl_packets, hci_stack.packet_types);
}
}
if (COMMAND_COMPLETE_EVENT(packet, hci_write_scan_enable)){
hci_emit_discoverable_enabled(hci_stack.discoverable);
}
break;
case HCI_EVENT_COMMAND_STATUS:
// get num cmd packets
// log_info("HCI_EVENT_COMMAND_STATUS cmds - old %u - new %u\n", hci_stack.num_cmd_packets, packet[3]);
hci_stack.num_cmd_packets = packet[3];
break;
case HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS:
for (i=0; i<packet[2];i++){
handle = READ_BT_16(packet, 3 + 2*i);
uint16_t num_packets = READ_BT_16(packet, 3 + packet[2]*2 + 2*i);
conn = connection_for_handle(handle);
if (!conn){
log_error("hci_number_completed_packet lists unused con handle %u\n", handle);
continue;
}
conn->num_acl_packets_sent -= num_packets;
// log_info("hci_number_completed_packet %u processed for handle %u, outstanding %u\n", num_packets, handle, conn->num_acl_packets_sent);
}
break;
case HCI_EVENT_CONNECTION_REQUEST:
bt_flip_addr(addr, &packet[2]);
// TODO: eval COD 8-10
link_type = packet[11];
log_info("Connection_incoming: %s, type %u\n", bd_addr_to_str(addr), link_type);
if (link_type == 1) { // ACL
conn = connection_for_address(addr);
if (!conn) {
conn = create_connection_for_addr(addr);
}
if (!conn) {
// CONNECTION REJECTED DUE TO LIMITED RESOURCES (0X0D)
hci_stack.decline_reason = 0x0d;
BD_ADDR_COPY(hci_stack.decline_addr, addr);
break;
}
conn->state = RECEIVED_CONNECTION_REQUEST;
hci_run();
} else {
// SYNCHRONOUS CONNECTION LIMIT TO A DEVICE EXCEEDED (0X0A)
hci_stack.decline_reason = 0x0a;
BD_ADDR_COPY(hci_stack.decline_addr, addr);
}
break;
case HCI_EVENT_CONNECTION_COMPLETE:
// Connection management
bt_flip_addr(addr, &packet[5]);
log_info("Connection_complete (status=%u) %s\n", packet[2], bd_addr_to_str(addr));
conn = connection_for_address(addr);
if (conn) {
if (!packet[2]){
conn->state = OPEN;
conn->con_handle = READ_BT_16(packet, 3);
#ifdef HAVE_TICK
// restart timer
run_loop_set_timer(&conn->timeout, HCI_CONNECTION_TIMEOUT_MS);
run_loop_add_timer(&conn->timeout);
#endif
//.........这里部分代码省略.........
开发者ID:ajsb85,项目名称:ioio,代码行数:101,代码来源:hci.c
注:本文中的bt_flip_addr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论