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
+ \r
+ bool IsACLConnection = (((Bluetooth_HCIEvent_ConnectionRequest_t*)&EventParams)->LinkType == 0x01);\r
+\r
+ /* Only accept the connection if it is a ACL (data) connection, a device is not already connected\r
+ and the user application has indicated that the connection should be allowed */\r
+ Bluetooth_HCIProcessingState = (Bluetooth_Connection.IsConnected || !(IsACLConnection) ||\r
+ !(CALLBACK_Bluetooth_ConnectionRequest(Bluetooth_TempDeviceAddress))) ?\r
Bluetooth_Conn_RejectConnection : Bluetooth_Conn_AcceptConnection;\r
\r
BT_HCI_DEBUG(">> Connection Request from Device %02X:%02X:%02X:%02X:%02X:%02X",\r
BT_HCI_DEBUG("Enter State: Bluetooth_Conn_RejectConnection", NULL);\r
\r
/* Copy over the temporary BT device address saved from the Connection Request event, indicate failure\r
- to accept the connection due to limited device resources */\r
+ to accept the connection due to limited device resources or incorrect device address */\r
Bluetooth_HCICommand_RejectConnectionRequest_t RejectConnectionParams;\r
memcpy(RejectConnectionParams.RemoteAddress, Bluetooth_TempDeviceAddress, sizeof(RejectConnectionParams.RemoteAddress));\r
- RejectConnectionParams.Reason = ERROR_LIMITED_RESOURCES;\r
+ RejectConnectionParams.Reason = Bluetooth_Connection.IsConnected ? ERROR_LIMITED_RESOURCES : ERROR_UNACCEPTABLE_BDADDR;\r
\r
/* Send the command to reject the remote connection request */\r
Bluetooth_SendHCICommand(&RejectConnectionParams, sizeof(Bluetooth_HCICommand_RejectConnectionRequest_t));\r