Hi,
I checked for the cases , below is the code I used and the output from the debugger
static void PacketHandler(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=1;
uint16_t mtu;
uint16_t handle;
uint16_t psm;
uint16_t local_cid;
uint16_t remote_cid;
int i,j;
switch (packet_type) {
case RFCOMM_DATA_PACKET:
goodprintf("Received RFCOMM data on channel id %u, size %u\n", channel, size);
hexdump(packet, size);
break;
case L2CAP_EVENT_CHANNEL_OPENED :
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);
remote_cid = READ_BT_16(packet, 14);
if (packet[2] == 0) {
goodprintf("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));
l2cap_send_internal(local_cid,accel_buffer,sizeof (accel_buffer));
} else {
goodprintf("L2CAP connection to device %s failed. status code %u\n", bd_addr_to_str(event_addr), packet[2]);
//exit(1);
}
break;
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_authentication_enable, 1);
hci_send_cmd(&hci_write_local_name, "BlueMSP-Demo");
}
break;
case HCI_EVENT_INQUIRY_RESULT:
// ignore further results
//if (haveDevice) break;
// ignore none Devices
//if ((packet[12] & 0x40) != 0x40 || packet[13] != 0x25) break;
// flip addr
bt_flip_addr(event_addr, &packet[3]);
// show
goodprintf("Device:\n\r");
// addr
j=0;
for (i=0;i<6;i++){
lineBuffer[j++] = hexMap[ event_addr[i] >> 4 ];
lineBuffer[j++] = hexMap[ event_addr[i] & 0x0f ];
if (i<5) lineBuffer[j++] = ':';
}
lineBuffer[j++] = 0;
goodprintf(lineBuffer);
hci_send_cmd(&hci_inquiry_cancel);
break;
case HCI_EVENT_INQUIRY_COMPLETE:
goodprintf("No Device found :(");
break;
case HCI_EVENT_COMMAND_COMPLETE:
if (COMMAND_COMPLETE_EVENT(packet, hci_write_local_name)){
goodprintf("Inquiry");
//state = inquiry;
hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, 30, 0);
break;
}
if (COMMAND_COMPLETE_EVENT(packet, hci_inquiry_cancel)){
hci_send_cmd(&hci_write_authentication_enable, 1);
break;
}
if (COMMAND_COMPLETE_EVENT(packet, hci_write_authentication_enable)){
hci_discoverable_control(1);
goodprintf("Connecting");
rfcomm_create_channel_internal(NULL,&event_addr,rfcomm_channel_nr);
break;
}
break;
case HCI_EVENT_LINK_KEY_REQUEST:
// deny link key request
goodprintf("Link key request\n\r");
bt_flip_addr(event_addr, &packet[2]);
hci_send_cmd(&hci_link_key_request_negative_reply, &event_addr);
break;
case HCI_EVENT_PIN_CODE_REQUEST:
// inform about pin code request
goodprintf( "PIN = 1234");
goodprintf("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, "1234");
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);
goodprintf("RFCOMM channel %u requested for %s\n\r", 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]) {
goodprintf("RFCOMM channel open failed, status %u\n\r", packet[2]);
goodprintf("Connection failed :(");
} else {
rfcomm_channel_id = READ_BT_16(packet, 12);
mtu = READ_BT_16(packet, 14);
goodprintf("\n\rRFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n\r", rfcomm_channel_id, mtu);
}
//rfcomm_send_internal(rfcomm_channel_id,accel_buffer,sizeof (accel_buffer));
break;
/*
case DAEMON_EVENT_HCI_PACKET_SENT:
case RFCOMM_EVENT_CREDITS:
if (!rfcomm_channel_id) break;
// try send
err = rfcomm_send_internal(rfcomm_channel_id, (uint8_t *)accel_buffer, sizeof(accel_buffer));
switch (err){
case 0:
//prepare_accel_packet();
break;
case BTSTACK_ACL_BUFFERS_FULL:
break;
default:
goodprintf("rfcomm_send_internal() -> err %d\n\r", err);
break;
}
break;
*/
case RFCOMM_EVENT_CHANNEL_CLOSED:
rfcomm_channel_id = 0;
break;
case HCI_EVENT_DISCONNECTION_COMPLETE:
// connection closed -> quit test app
goodprintf("Basebank connection closed\n");
break;
default:
break;
}
break;
default:
break;
}
}
================================================
the output from the debugger is:
nfo: hci_power_control: 1, current mode 0
Info: hci_run: init script done
Info: Local Address, Status: 0x00: Addr: 00:18:34:2F:9B:46
ERROR: hci_read_buffer_size: used size 52, count 4, packet types 331E
InquiryDevice:
00:0E:6D:BA:87:AFConnectingInfo: rfcomm_create_channel_internal to 00:0E:6D:BA:87:AF, at channel #01, flow control 0, init credits 48
Info: rfcomm_max_frame_size_for_l2cap_mtu: 48 -> 43
Info: rfcomm_channel_create for service 0 1 --- begin
Info: Create_connection to 00:0E:6D:BA:87:AF
Info: Connection_complete (status=4) 00:0E:6D:BA:87:AF
Info: L2CAP_EVENT_CHANNEL_OPENED for PSM_RFCOMM
Info: L2CAP_EVENT_CHANNEL_OPENED: outgoing connection
after that it freezes and nothing happens, when is says connection_complete (status=4) what does that mean. Also did the channel open or what? When is it supposed to check for the PIN code ? thanks