mark hci cmd templates as const to save RAM

This commit is contained in:
matthias.ringwald 2010-08-08 18:10:45 +00:00
parent 856c7144e5
commit fe35119d8a
4 changed files with 109 additions and 109 deletions

View File

@ -190,56 +190,56 @@ typedef enum {
// HCI Commands - see hci_cmds.c for info on parameters
extern hci_cmd_t btstack_get_state;
extern hci_cmd_t btstack_set_power_mode;
extern hci_cmd_t btstack_set_acl_capture_mode;
extern hci_cmd_t btstack_get_version;
extern hci_cmd_t btstack_get_system_bluetooth_enabled;
extern hci_cmd_t btstack_set_system_bluetooth_enabled;
extern const hci_cmd_t btstack_get_state;
extern const hci_cmd_t btstack_set_power_mode;
extern const hci_cmd_t btstack_set_acl_capture_mode;
extern const hci_cmd_t btstack_get_version;
extern const hci_cmd_t btstack_get_system_bluetooth_enabled;
extern const hci_cmd_t btstack_set_system_bluetooth_enabled;
extern hci_cmd_t hci_accept_connection_request;
extern hci_cmd_t hci_authentication_requested;
extern hci_cmd_t hci_create_connection;
extern hci_cmd_t hci_create_connection_cancel;
extern hci_cmd_t hci_delete_stored_link_key;
extern hci_cmd_t hci_disconnect;
extern hci_cmd_t hci_host_buffer_size;
extern hci_cmd_t hci_inquiry;
extern hci_cmd_t hci_inquiry_cancel;
extern hci_cmd_t hci_link_key_request_negative_reply;
extern hci_cmd_t hci_link_key_request_reply;
extern hci_cmd_t hci_pin_code_request_reply;
extern hci_cmd_t hci_pin_code_request_negative_reply;
extern hci_cmd_t hci_qos_setup;
extern hci_cmd_t hci_read_bd_addr;
extern hci_cmd_t hci_read_buffer_size;
extern hci_cmd_t hci_read_link_policy_settings;
extern hci_cmd_t hci_read_link_supervision_timeout;
extern hci_cmd_t hci_remote_name_request;
extern hci_cmd_t hci_remote_name_request_cancel;
extern hci_cmd_t hci_reset;
extern hci_cmd_t hci_role_discovery;
extern hci_cmd_t hci_set_event_mask;
extern hci_cmd_t hci_switch_role_command;
extern hci_cmd_t hci_write_authentication_enable;
extern hci_cmd_t hci_write_class_of_device;
extern hci_cmd_t hci_write_extended_inquiry_response;
extern hci_cmd_t hci_write_inquiry_mode;
extern hci_cmd_t hci_write_link_policy_settings;
extern hci_cmd_t hci_write_link_supervision_timeout;
extern hci_cmd_t hci_write_local_name;
extern hci_cmd_t hci_write_page_timeout;
extern hci_cmd_t hci_write_scan_enable;
extern hci_cmd_t hci_write_simple_pairing_mode;
extern const hci_cmd_t hci_accept_connection_request;
extern const hci_cmd_t hci_authentication_requested;
extern const hci_cmd_t hci_create_connection;
extern const hci_cmd_t hci_create_connection_cancel;
extern const hci_cmd_t hci_delete_stored_link_key;
extern const hci_cmd_t hci_disconnect;
extern const hci_cmd_t hci_host_buffer_size;
extern const hci_cmd_t hci_inquiry;
extern const hci_cmd_t hci_inquiry_cancel;
extern const hci_cmd_t hci_link_key_request_negative_reply;
extern const hci_cmd_t hci_link_key_request_reply;
extern const hci_cmd_t hci_pin_code_request_reply;
extern const hci_cmd_t hci_pin_code_request_negative_reply;
extern const hci_cmd_t hci_qos_setup;
extern const hci_cmd_t hci_read_bd_addr;
extern const hci_cmd_t hci_read_buffer_size;
extern const hci_cmd_t hci_read_link_policy_settings;
extern const hci_cmd_t hci_read_link_supervision_timeout;
extern const hci_cmd_t hci_remote_name_request;
extern const hci_cmd_t hci_remote_name_request_cancel;
extern const hci_cmd_t hci_reset;
extern const hci_cmd_t hci_role_discovery;
extern const hci_cmd_t hci_set_event_mask;
extern const hci_cmd_t hci_switch_role_command;
extern const hci_cmd_t hci_write_authentication_enable;
extern const hci_cmd_t hci_write_class_of_device;
extern const hci_cmd_t hci_write_extended_inquiry_response;
extern const hci_cmd_t hci_write_inquiry_mode;
extern const hci_cmd_t hci_write_link_policy_settings;
extern const hci_cmd_t hci_write_link_supervision_timeout;
extern const hci_cmd_t hci_write_local_name;
extern const hci_cmd_t hci_write_page_timeout;
extern const hci_cmd_t hci_write_scan_enable;
extern const hci_cmd_t hci_write_simple_pairing_mode;
extern hci_cmd_t l2cap_accept_connection;
extern hci_cmd_t l2cap_create_channel;
extern hci_cmd_t l2cap_decline_connection;
extern hci_cmd_t l2cap_disconnect;
extern hci_cmd_t l2cap_register_service;
extern hci_cmd_t l2cap_unregister_service;
extern const hci_cmd_t l2cap_accept_connection;
extern const hci_cmd_t l2cap_create_channel;
extern const hci_cmd_t l2cap_decline_connection;
extern const hci_cmd_t l2cap_disconnect;
extern const hci_cmd_t l2cap_register_service;
extern const hci_cmd_t l2cap_unregister_service;
extern hci_cmd_t sdp_register_service_record;
extern hci_cmd_t sdp_unregister_service_record;
extern const hci_cmd_t sdp_register_service_record;
extern const hci_cmd_t sdp_unregister_service_record;

View File

@ -592,7 +592,7 @@ int hci_send_cmd_packet(uint8_t *packet, int size){
/**
* pre: numcmds >= 0 - it's allowed to send a command to the controller
*/
int hci_send_cmd(hci_cmd_t *cmd, ...){
int hci_send_cmd(const hci_cmd_t *cmd, ...){
va_list argptr;
va_start(argptr, cmd);
uint8_t * hci_cmd_buffer = hci_stack.hci_cmd_buffer;

View File

@ -59,7 +59,7 @@
* P: 16 byte Pairing code
* S: Service Record (Data Element Sequence)
*/
uint16_t hci_create_cmd_internal(uint8_t *hci_cmd_buffer, hci_cmd_t *cmd, va_list argptr){
uint16_t hci_create_cmd_internal(uint8_t *hci_cmd_buffer, const hci_cmd_t *cmd, va_list argptr){
hci_cmd_buffer[0] = cmd->opcode & 0xff;
hci_cmd_buffer[1] = cmd->opcode >> 8;
@ -163,56 +163,56 @@ uint16_t hci_create_cmd(uint8_t *hci_cmd_buffer, hci_cmd_t *cmd, ...){
/**
* Link Control Commands
*/
hci_cmd_t hci_inquiry = {
const hci_cmd_t hci_inquiry = {
OPCODE(OGF_LINK_CONTROL, 0x01), "311"
// LAP, Inquiry length, Num_responses
};
hci_cmd_t hci_inquiry_cancel = {
const hci_cmd_t hci_inquiry_cancel = {
OPCODE(OGF_LINK_CONTROL, 0x02), ""
// no params
};
hci_cmd_t hci_create_connection = {
const hci_cmd_t hci_create_connection = {
OPCODE(OGF_LINK_CONTROL, 0x05), "B21121"
// BD_ADDR, Packet_Type, Page_Scan_Repetition_Mode, Reserved, Clock_Offset, Allow_Role_Switch
};
hci_cmd_t hci_disconnect = {
const hci_cmd_t hci_disconnect = {
OPCODE(OGF_LINK_CONTROL, 0x06), "H1"
// Handle, Reason: 0x05, 0x13-0x15, 0x1a, 0x29
// see Errors Codes in BT Spec Part D
};
hci_cmd_t hci_create_connection_cancel = {
const hci_cmd_t hci_create_connection_cancel = {
OPCODE(OGF_LINK_CONTROL, 0x08), "B"
// BD_ADDR
};
hci_cmd_t hci_accept_connection_request = {
const hci_cmd_t hci_accept_connection_request = {
OPCODE(OGF_LINK_CONTROL, 0x09), "B1"
// BD_ADDR, Role: become master, stay slave
};
hci_cmd_t hci_link_key_request_reply = {
const hci_cmd_t hci_link_key_request_reply = {
OPCODE(OGF_LINK_CONTROL, 0x0b), "BP"
// BD_ADDR, LINK_KEY
};
hci_cmd_t hci_link_key_request_negative_reply = {
const hci_cmd_t hci_link_key_request_negative_reply = {
OPCODE(OGF_LINK_CONTROL, 0x0c), "B"
// BD_ADDR
};
hci_cmd_t hci_pin_code_request_reply = {
const hci_cmd_t hci_pin_code_request_reply = {
OPCODE(OGF_LINK_CONTROL, 0x0d), "B1P"
// BD_ADDR, pin length, PIN: c-string
};
hci_cmd_t hci_pin_code_request_negative_reply = {
const hci_cmd_t hci_pin_code_request_negative_reply = {
OPCODE(OGF_LINK_CONTROL, 0x0e), "B"
// BD_ADDR
};
hci_cmd_t hci_authentication_requested = {
const hci_cmd_t hci_authentication_requested = {
OPCODE(OGF_LINK_CONTROL, 0x11), "H"
// Handle
};
hci_cmd_t hci_remote_name_request = {
const hci_cmd_t hci_remote_name_request = {
OPCODE(OGF_LINK_CONTROL, 0x19), "B112"
// BD_ADDR, Page_Scan_Repetition_Mode, Reserved, Clock_Offset
};
hci_cmd_t hci_remote_name_request_cancel = {
const hci_cmd_t hci_remote_name_request_cancel = {
OPCODE(OGF_LINK_CONTROL, 0x1A), "B"
// BD_ADDR
};
@ -220,24 +220,24 @@ OPCODE(OGF_LINK_CONTROL, 0x1A), "B"
/**
* Link Policy Commands
*/
hci_cmd_t hci_qos_setup = {
const hci_cmd_t hci_qos_setup = {
OPCODE(OGF_LINK_POLICY, 0x07), "H114444"
// handle, flags, service_type, token rate (bytes/s), peak bandwith (bytes/s),
// latency (us), delay_variation (us)
};
hci_cmd_t hci_role_discovery = {
const hci_cmd_t hci_role_discovery = {
OPCODE(OGF_LINK_POLICY, 0x09), "H"
// handle
};
hci_cmd_t hci_switch_role_command= {
const hci_cmd_t hci_switch_role_command= {
OPCODE(OGF_LINK_POLICY, 0x0b), "B1"
// handle, role: {0=master,1=slave}
};
hci_cmd_t hci_read_link_policy_settings = {
const hci_cmd_t hci_read_link_policy_settings = {
OPCODE(OGF_LINK_POLICY, 0x0c), "H"
// handle
};
hci_cmd_t hci_write_link_policy_settings = {
const hci_cmd_t hci_write_link_policy_settings = {
OPCODE(OGF_LINK_POLICY, 0x0d), "H2"
// handle, settings
};
@ -245,59 +245,59 @@ OPCODE(OGF_LINK_POLICY, 0x0d), "H2"
/**
* Controller & Baseband Commands
*/
hci_cmd_t hci_set_event_mask = {
const hci_cmd_t hci_set_event_mask = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x01), "44"
// event_mask lower 4 octets, higher 4 bytes
};
hci_cmd_t hci_reset = {
const hci_cmd_t hci_reset = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x03), ""
// no params
};
hci_cmd_t hci_delete_stored_link_key = {
const hci_cmd_t hci_delete_stored_link_key = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x12), "B1"
// BD_ADDR, Delete_All_Flag
};
hci_cmd_t hci_write_local_name = {
const hci_cmd_t hci_write_local_name = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x13), "N"
// Local name (UTF-8, Null Terminated, max 248 octets)
};
hci_cmd_t hci_write_page_timeout = {
const hci_cmd_t hci_write_page_timeout = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x18), "2"
// Page_Timeout * 0.625 ms
};
hci_cmd_t hci_write_scan_enable = {
const hci_cmd_t hci_write_scan_enable = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x1A), "1"
// Scan_enable: no, inq, page, inq+page
};
hci_cmd_t hci_write_authentication_enable = {
const hci_cmd_t hci_write_authentication_enable = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x20), "1"
// Authentication_Enable
};
hci_cmd_t hci_write_class_of_device = {
const hci_cmd_t hci_write_class_of_device = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x24), "3"
// Class of Device
};
hci_cmd_t hci_host_buffer_size = {
const hci_cmd_t hci_host_buffer_size = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x33), "2122"
// Host_ACL_Data_Packet_Length:, Host_Synchronous_Data_Packet_Length:, Host_Total_Num_ACL_Data_Packets:, Host_Total_Num_Synchronous_Data_Packets:
};
hci_cmd_t hci_read_link_supervision_timeout = {
const hci_cmd_t hci_read_link_supervision_timeout = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x36), "H"
// handle
};
hci_cmd_t hci_write_link_supervision_timeout = {
const hci_cmd_t hci_write_link_supervision_timeout = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x37), "H2"
// handle, Range for N: 0x0001 0xFFFF Time (Range: 0.625ms 40.9 sec)
};
hci_cmd_t hci_write_inquiry_mode = {
const hci_cmd_t hci_write_inquiry_mode = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x45), "1"
// Inquiry mode: 0x00 = standard, 0x01 = with RSSI, 0x02 = extended
};
hci_cmd_t hci_write_extended_inquiry_response = {
const hci_cmd_t hci_write_extended_inquiry_response = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x52), "1E"
// FEC_Required, Exstended Inquiry Response
};
hci_cmd_t hci_write_simple_pairing_mode = {
const hci_cmd_t hci_write_simple_pairing_mode = {
OPCODE(OGF_CONTROLLER_BASEBAND, 0x56), "1"
// mode: 0 = off, 1 = on
};
@ -305,73 +305,73 @@ OPCODE(OGF_CONTROLLER_BASEBAND, 0x56), "1"
/**
* Informational Parameters
*/
hci_cmd_t hci_read_buffer_size = {
const hci_cmd_t hci_read_buffer_size = {
OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x05), ""
// no params
};
hci_cmd_t hci_read_bd_addr = {
const hci_cmd_t hci_read_bd_addr = {
OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x09), ""
// no params
};
// BTstack commands
hci_cmd_t btstack_get_state = {
const hci_cmd_t btstack_get_state = {
OPCODE(OGF_BTSTACK, BTSTACK_GET_STATE), ""
// no params ->
};
hci_cmd_t btstack_set_power_mode = {
const hci_cmd_t btstack_set_power_mode = {
OPCODE(OGF_BTSTACK, BTSTACK_SET_POWER_MODE), "1"
// mode: 0 = off, 1 = on
};
hci_cmd_t btstack_set_acl_capture_mode = {
const hci_cmd_t btstack_set_acl_capture_mode = {
OPCODE(OGF_BTSTACK, BTSTACK_SET_ACL_CAPTURE_MODE), "1"
// mode: 0 = off, 1 = on
};
hci_cmd_t btstack_get_version = {
const hci_cmd_t btstack_get_version = {
OPCODE(OGF_BTSTACK, BTSTACK_GET_VERSION), ""
};
hci_cmd_t btstack_get_system_bluetooth_enabled = {
const hci_cmd_t btstack_get_system_bluetooth_enabled = {
OPCODE(OGF_BTSTACK, BTSTACK_GET_SYSTEM_BLUETOOTH_ENABLED), ""
};
hci_cmd_t btstack_set_system_bluetooth_enabled = {
const hci_cmd_t btstack_set_system_bluetooth_enabled = {
OPCODE(OGF_BTSTACK, BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED), "1"
};
hci_cmd_t l2cap_create_channel = {
const hci_cmd_t l2cap_create_channel = {
OPCODE(OGF_BTSTACK, L2CAP_CREATE_CHANNEL), "B2"
// @param bd_addr(48), psm (16)
};
hci_cmd_t l2cap_disconnect = {
const hci_cmd_t l2cap_disconnect = {
OPCODE(OGF_BTSTACK, L2CAP_DISCONNECT), "21"
// @param channel(16), reason(8)
};
hci_cmd_t l2cap_register_service = {
const hci_cmd_t l2cap_register_service = {
OPCODE(OGF_BTSTACK, L2CAP_REGISTER_SERVICE), "22"
// @param psm (16), mtu (16)
};
hci_cmd_t l2cap_unregister_service = {
const hci_cmd_t l2cap_unregister_service = {
OPCODE(OGF_BTSTACK, L2CAP_UNREGISTER_SERVICE), "2"
// @param psm (16)
};
hci_cmd_t l2cap_accept_connection = {
const hci_cmd_t l2cap_accept_connection = {
OPCODE(OGF_BTSTACK, L2CAP_ACCEPT_CONNECTION), "2"
// @param source cid (16)
};
hci_cmd_t l2cap_decline_connection = {
const hci_cmd_t l2cap_decline_connection = {
OPCODE(OGF_BTSTACK, L2CAP_DECLINE_CONNECTION), "21"
// @param source cid (16), reason(8)
};
hci_cmd_t sdp_register_service_record = {
const hci_cmd_t sdp_register_service_record = {
OPCODE(OGF_BTSTACK, SDP_REGISTER_SERVICE_RECORD), "S"
// @param service record handle (DES)
};
hci_cmd_t sdp_unregister_service_record = {
const hci_cmd_t sdp_unregister_service_record = {
OPCODE(OGF_BTSTACK, SDP_UNREGISTER_SERVICE_RECORD), "4"
// @param service record handle (32)
};

View File

@ -180,7 +180,7 @@ uint16_t l2cap_get_remote_mtu_for_local_cid(uint16_t local_cid){
}
int l2cap_send_signaling_packet(hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, ...){
// printf("l2cap_send_signaling_packet type %u\n", cmd);
// log_dbg("l2cap_send_signaling_packet type %u\n", cmd);
va_list argptr;
va_start(argptr, identifier);
uint16_t len = l2cap_create_signaling_internal(sig_buffer, handle, cmd, identifier, argptr);
@ -415,23 +415,23 @@ static void l2cap_handle_disconnect_request(l2cap_channel_t *channel, uint16_t i
static void l2cap_handle_connection_request(hci_con_handle_t handle, uint8_t sig_id, uint16_t psm, uint16_t source_cid){
// printf("l2cap_handle_connection_request for handle %u, psm %u cid %u\n", handle, psm, source_cid);
// log_dbg("l2cap_handle_connection_request for handle %u, psm %u cid %u\n", handle, psm, source_cid);
l2cap_service_t *service = l2cap_get_service(psm);
if (!service) {
// 0x0002 PSM not supported
// printf("l2cap_handle_connection_request no PSM for psm %u/n", psm);
// log_dbg("l2cap_handle_connection_request no PSM for psm %u/n", psm);
l2cap_send_signaling_packet(handle, CONNECTION_RESPONSE, sig_id, 0, 0, 0x0002, 0);
return;
}
hci_connection_t * hci_connection = connection_for_handle( handle );
if (!hci_connection) {
fprintf(stderr, "no hci_connection for handle %u\n", handle);
log_err("no hci_connection for handle %u\n", handle);
// TODO: emit error
return;
}
// alloc structure
// printf("l2cap_handle_connection_request register channel\n");
// log_dbg("l2cap_handle_connection_request register channel\n");
l2cap_channel_t * channel = malloc(sizeof(l2cap_channel_t));
// TODO: emit error event
if (!channel) return;
@ -462,7 +462,7 @@ static void l2cap_handle_connection_request(hci_con_handle_t handle, uint8_t sig
void l2cap_accept_connection_internal(uint16_t local_cid){
l2cap_channel_t * channel = l2cap_get_channel_for_local_cid(local_cid);
if (!channel) {
fprintf(stderr, "l2cap_accept_connection_internal called but local_cid 0x%x not found", local_cid);
log_err("l2cap_accept_connection_internal called but local_cid 0x%x not found", local_cid);
return;
}
@ -474,13 +474,13 @@ void l2cap_accept_connection_internal(uint16_t local_cid){
channel->state = L2CAP_STATE_WAIT_CONFIG_REQ_RSP_OR_CONFIG_REQ;
l2cap_send_signaling_packet(channel->handle, CONFIGURE_REQUEST, channel->sig_id, channel->remote_cid, 0, 4, &config_options);
// printf("new state %u\n", channel->state);
// log_dbg("new state %u\n", channel->state);
}
void l2cap_decline_connection_internal(uint16_t local_cid, uint8_t reason){
l2cap_channel_t * channel = l2cap_get_channel_for_local_cid( local_cid);
if (!channel) {
fprintf(stderr, "l2cap_decline_connection_internal called but local_cid 0x%x not found", local_cid);
log_err( "l2cap_decline_connection_internal called but local_cid 0x%x not found", local_cid);
return;
}
l2cap_send_signaling_packet(channel->handle, CONNECTION_RESPONSE, channel->sig_id, 0, 0, reason, 0);
@ -500,7 +500,7 @@ void l2cap_signaling_handle_configure_request(l2cap_channel_t *channel, uint8_t
// MTU { type(8): 1, len(8):2, MTU(16) }
if ((type & 0x7f) == 1 && length == 2){
channel->remote_mtu = READ_BT_16(command, pos);
// printf("l2cap cid %u, remote mtu %u\n", channel->local_cid, channel->remote_mtu);
// log_dbg("l2cap cid %u, remote mtu %u\n", channel->local_cid, channel->remote_mtu);
}
pos += length;
}
@ -517,7 +517,7 @@ void l2cap_signaling_handler_channel(l2cap_channel_t *channel, uint8_t *command)
uint8_t identifier = command[L2CAP_SIGNALING_COMMAND_SIGID_OFFSET];
uint16_t result = 0;
// printf("signaling handler code %u\n", code);
// log_dbg("signaling handler code %u\n", code);
switch (channel->state) {
@ -635,7 +635,7 @@ void l2cap_signaling_handler_channel(l2cap_channel_t *channel, uint8_t *command)
default:
break;
}
// printf("new state %u\n", channel->state);
// log_dbg("new state %u\n", channel->state);
}