+ BT_HCI_DEBUG("Event Code: 0x%02X", HCIEventHeader.EventCode);\r
+ \r
+ switch (HCIEventHeader.EventCode)\r
+ {\r
+ case EVENT_COMMAND_COMPLETE:\r
+ Bluetooth_HCIProcessingState = Bluetooth_HCINextState;\r
+\r
+ BT_HCI_DEBUG(">> Command Complete (Opcode 0x%04x)", \r
+ ((Bluetooth_HCIEvent_CommandComplete_t*)&EventParams)->Opcode);\r
+ break;\r
+ case EVENT_COMMAND_STATUS:\r
+ /* If the execution of a command failed, reset the stack */\r
+ if (((Bluetooth_HCIEvent_CommandStatus_t*)&EventParams)->Status)\r
+ Bluetooth_HCIProcessingState = Bluetooth_Init;\r
+\r
+ BT_HCI_DEBUG(">> Command Status: 0x%02X",\r
+ ((Bluetooth_HCIEvent_CommandStatus_t*)&EventParams)->Status); \r
+ break;\r
+ case EVENT_CONNECTION_REQUEST:\r
+ /* Need to store the remote device's BT address in a temporary buffer for later use */\r
+ memcpy(Bluetooth_TempDeviceAddress,\r
+ &((Bluetooth_HCIEvent_ConnectionRequest_t*)&EventParams)->RemoteAddress,\r
+ sizeof(Bluetooth_TempDeviceAddress));\r
+ \r
+ /* Only accept the connection if it is a ACL (data) connection */\r
+ Bluetooth_HCIProcessingState = (Bluetooth_Connection.IsConnected ||\r
+ (((Bluetooth_HCIEvent_ConnectionRequest_t*)&EventParams)->LinkType != 0x01)) ?\r
+ Bluetooth_Conn_RejectConnection : Bluetooth_Conn_AcceptConnection;\r
+\r
+ BT_HCI_DEBUG(">> Connection Request from Device %02X:%02X:%02X:%02X:%02X:%02X",\r
+ Bluetooth_TempDeviceAddress[5], Bluetooth_TempDeviceAddress[4], Bluetooth_TempDeviceAddress[3],\r
+ Bluetooth_TempDeviceAddress[2], Bluetooth_TempDeviceAddress[1], Bluetooth_TempDeviceAddress[0]);\r
+ break;\r
+ case EVENT_PIN_CODE_REQUEST:\r
+ /* Need to store the remote device's BT address in a temporary buffer for later use */\r
+ memcpy(Bluetooth_TempDeviceAddress,\r
+ &((Bluetooth_HCIEvent_PinCodeRequest_t*)&EventParams)->RemoteAddress,\r
+ sizeof(Bluetooth_TempDeviceAddress));\r
+\r
+ Bluetooth_HCIProcessingState = Bluetooth_Conn_SendPINCode;\r
+\r
+ BT_HCI_DEBUG(">> PIN Request from Device %02X:%02X:%02X:%02X:%02X:%02X", \r
+ Bluetooth_TempDeviceAddress[5], Bluetooth_TempDeviceAddress[4], Bluetooth_TempDeviceAddress[3],\r
+ Bluetooth_TempDeviceAddress[2], Bluetooth_TempDeviceAddress[1], Bluetooth_TempDeviceAddress[0]);\r
+ break;\r
+ case EVENT_CONNECTION_COMPLETE:\r
+ /* Need to store the remote device's BT address in a temporary buffer for later use */\r
+ memcpy(Bluetooth_Connection.RemoteAddress,\r
+ &((Bluetooth_HCIEvent_ConnectionComplete_t*)&EventParams)->RemoteAddress,\r
+ sizeof(Bluetooth_TempDeviceAddress));\r
+\r
+ /* Store the created connection handle and indicate that the connection has been established */\r
+ Bluetooth_Connection.ConnectionHandle = ((Bluetooth_HCIEvent_ConnectionComplete_t*)&EventParams)->ConnectionHandle;\r
+ Bluetooth_Connection.IsConnected = true;\r
+\r
+ BT_HCI_DEBUG(">> Connection Complete to Device %02X:%02X:%02X:%02X:%02X:%02X, Handle 0x%04x", \r
+ Bluetooth_Connection.RemoteAddress[5], Bluetooth_Connection.RemoteAddress[4],\r
+ Bluetooth_Connection.RemoteAddress[3], Bluetooth_Connection.RemoteAddress[2],\r
+ Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0],\r
+ Bluetooth_Connection.ConnectionHandle);\r
+ break;\r
+ case EVENT_DISCONNECTION_COMPLETE:\r
+ BT_HCI_DEBUG(">> Disconnection Complete", NULL);\r
+\r
+ /* Device disconnected, indicate connection information no longer valid */\r
+ Bluetooth_Connection.IsConnected = false;\r
+ \r
+ Bluetooth_HCIProcessingState = Bluetooth_Init;\r
+ break; \r
+ }\r
+ }\r
+ \r
+ Pipe_Freeze();\r
+ \r