/* * command_complete(): * * Called by HCI when an issued command has completed during the initialization of the * host controller. Waits for a connection from remote device once connected. * * Event Sequence: * HCI Reset -> Read Buf Size -> Read BDAddr -> Set Ev Filter -+ * +-----------------------------------------------------------+ * |_/-> Write CoD -> Cng Local Name -> Write Pg Timeout -> Inq -> Complete * \-> Scan Enable -> Complete */ err_t command_complete(void *arg, struct hci_pcb *pcb, u8_t ogf, u8_t ocf, u8_t result) { u8_t cod_spp[] = {0x80,0x08,0x04}; u8_t devname[] = "PIC24F------"; u8_t n1, n2, n3; u8_t flag = HCI_SET_EV_FILTER_AUTOACC_ROLESW; switch(ogf) { case HCI_INFO_PARAM: switch(ocf) { case HCI_READ_BUFFER_SIZE: if(result == HCI_SUCCESS) { LWIP_DEBUGF(BT_SPP_DEBUG, ("successful HCI_READ_BUFFER_SIZE.\n")); hci_read_bd_addr(read_bdaddr_complete); } else { LWIP_DEBUGF(BT_SPP_DEBUG, ("Unsuccessful HCI_READ_BUFFER_SIZE.\n")); return ERR_CONN; } break; case HCI_READ_BD_ADDR: if(result == HCI_SUCCESS) { LWIP_DEBUGF(BT_SPP_DEBUG, ("successful HCI_READ_BD_ADDR.\n")); /* Make discoverable */ hci_set_event_filter(HCI_SET_EV_FILTER_CONNECTION, HCI_SET_EV_FILTER_ALLDEV, &flag); } else { LWIP_DEBUGF(BT_SPP_DEBUG, ("Unsuccessful HCI_READ_BD_ADDR.\n")); return ERR_CONN; } break; default: LWIP_DEBUGF(BT_SPP_DEBUG, ("Unknown HCI_INFO_PARAM command complete event\n")); break; } break; case HCI_HC_BB_OGF: switch(ocf) { case HCI_RESET: if(result == HCI_SUCCESS) { LWIP_DEBUGF(BT_SPP_DEBUG, ("successful HCI_RESET.\n")); hci_read_buffer_size(); } else { LWIP_DEBUGF(BT_SPP_DEBUG, ("Unsuccessful HCI_RESET.\n")); return ERR_CONN; } break; case HCI_WRITE_SCAN_ENABLE: if(result == HCI_SUCCESS) { LWIP_DEBUGF(BT_SPP_DEBUG, ("successful HCI_WRITE_SCAN_ENABLE.\n")); hci_write_page_timeout(0x4000); /* 10.24s */ //hci_cmd_complete(NULL); /* Initialization done, don't come back */ } else { LWIP_DEBUGF(BT_SPP_DEBUG, ("Unsuccessful HCI_WRITE_SCAN_ENABLE.\n")); return ERR_CONN; } break; case HCI_SET_EVENT_FILTER: if(result == HCI_SUCCESS) { LWIP_DEBUGF(BT_SPP_DEBUG, ("successful HCI_SET_EVENT_FILTER.\n")); hci_write_cod(cod_spp); } else { LWIP_DEBUGF(BT_SPP_DEBUG, ("Unsuccessful HCI_SET_EVENT_FILTER.\n")); return ERR_CONN; } break; case HCI_CHANGE_LOCAL_NAME: if(result == HCI_SUCCESS) { LWIP_DEBUGF(BT_SPP_DEBUG, ("Successful HCI_CHANGE_LOCAL_NAME.\n")); hci_write_scan_enable(HCI_SCAN_EN_INQUIRY | HCI_SCAN_EN_PAGE); } else { LWIP_DEBUGF(BT_SPP_DEBUG, ("Unsuccessful HCI_CHANGE_LOCAL_NAME.\n")); return ERR_CONN; } break; case HCI_WRITE_COD: if(result == HCI_SUCCESS) { LWIP_DEBUGF(BT_SPP_DEBUG, ("Successful HCI_WRITE_COD.\n")); n1 = (u8_t)(bt_spp_state.bdaddr.addr[0] / 100); n2 = (u8_t)(bt_spp_state.bdaddr.addr[0] / 10) - n1 * 10; n3 = bt_spp_state.bdaddr.addr[0] - n1 * 100 - n2 * 10; devname[9] = '0' + n1; devname[10] = '0' + n2; devname[11] = '0' + n3; hci_change_local_name(devname, sizeof(devname)); } else { LWIP_DEBUGF(BT_SPP_DEBUG, ("Unsuccessful HCI_WRITE_COD.\n")); return ERR_CONN; } break; case HCI_WRITE_PAGE_TIMEOUT: if(result == HCI_SUCCESS) { LWIP_DEBUGF(BT_SPP_DEBUG, ("successful HCI_WRITE_PAGE_TIMEOUT.\n")); //hci_cmd_complete(NULL); /* Initialization done, don't come back */ hci_connection_complete(acl_conn_complete); LWIP_DEBUGF(BT_SPP_DEBUG, ("Initialization done.\n")); //LWIP_DEBUGF(BT_SPP_DEBUG, ("Discover other Bluetooth devices.\n")); //hci_inquiry(0x009E8B33, 0x04, 0x01, inquiry_complete); //FAILED???? } else { LWIP_DEBUGF(BT_SPP_DEBUG, ("Unsuccessful HCI_WRITE_PAGE_TIMEOUT.\n")); return ERR_CONN; } break; default: LWIP_DEBUGF(BT_SPP_DEBUG, ("Unknown HCI_HC_BB_OGF command complete event\n")); break; } break; default: LWIP_DEBUGF(BT_SPP_DEBUG, ("Unknown command complete event. OGF = 0x%x OCF = 0x%x\n", ogf, ocf)); break; } return ERR_OK; }
void hci_chip_active(void) { hci_read_buffer_size(); hci_host_buffer_size(ACL_DATA_PACKET_LENGTH,SCO_DATA_PACKET_LENGTH, ACL_TOTAL_PACKETS,SCO_TOTAL_PACKETS); hci_read_local_features(); }