aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Host/Incomplete/BluetoothHost
diff options
context:
space:
mode:
Diffstat (limited to 'Demos/Host/Incomplete/BluetoothHost')
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c14
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c23
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.h1
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h1
4 files changed, 33 insertions, 6 deletions
diff --git a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
index 016b43ca3..07172940c 100644
--- a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
+++ b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
@@ -238,6 +238,20 @@ void Bluetooth_DisconnectionComplete(void)
Bluetooth_Connection.RemoteAddress[1], Bluetooth_Connection.RemoteAddress[0]);
}
+/** Bluetooth stack callback event for a Bluetooth ACL Channel connection request. When is callback fires,
+ * the user application must indicate if the channel connection should be rejected or not, based on the
+ * protocol (PSM) value of the requested channel.
+ *
+ * \param PSM Protocol PSM value for the requested channel
+ *
+ * \return Boolean true to accept the channel connection request, false to reject it
+ */
+bool Bluetooth_ChannelConnectionRequest(uint16_t PSM)
+{
+ /* Always accept channel connection requests regardless of PSM */
+ return true;
+}
+
/** Bluetooth stack callback event for a non-signal ACL packet reception. This callback fires once a connection
* to a remote Bluetooth device has been made, and the remote device has sent a non-signalling ACL packet.
*
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c
index 108abbf3d..a8145c47d 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c
@@ -381,14 +381,26 @@ static inline void Bluetooth_Signal_ConnectionReq(BT_Signal_Header_t* SignalComm
}
}
}
+
+ uint8_t ChannelStatus = BT_CONNECTION_REFUSED_RESOURCES;
/* Reset the channel item contents only if a channel entry was found for it */
if (ChannelData != NULL)
{
- ChannelData->RemoteNumber = ConnectionRequest.SourceChannel;
- ChannelData->PSM = ConnectionRequest.PSM;
- ChannelData->LocalMTU = MAXIMUM_CHANNEL_MTU;
- ChannelData->State = Channel_Config_WaitConfig;
+ /* Check if the user application will allow the connection based on its PSM */
+ if (Bluetooth_ChannelConnectionRequest(ConnectionRequest.PSM))
+ {
+ ChannelData->RemoteNumber = ConnectionRequest.SourceChannel;
+ ChannelData->PSM = ConnectionRequest.PSM;
+ ChannelData->LocalMTU = MAXIMUM_CHANNEL_MTU;
+ ChannelData->State = Channel_Config_WaitConfig;
+
+ ChannelStatus = BT_CONNECTION_SUCCESSFUL;
+ }
+ else
+ {
+ ChannelStatus = BT_CONNECTION_REFUSED_PSM;
+ }
}
struct
@@ -405,8 +417,7 @@ static inline void Bluetooth_Signal_ConnectionReq(BT_Signal_Header_t* SignalComm
/* Fill out the Connection Response in the response packet */
ResponsePacket.ConnectionResponse.DestinationChannel = ChannelData->LocalNumber;
ResponsePacket.ConnectionResponse.SourceChannel = ChannelData->RemoteNumber;
- ResponsePacket.ConnectionResponse.Result = (ChannelData == NULL) ? BT_CONNECTION_REFUSED_RESOURCES :
- BT_CONNECTION_SUCCESSFUL;
+ ResponsePacket.ConnectionResponse.Result = ChannelStatus;
ResponsePacket.ConnectionResponse.Status = 0x00;
Bluetooth_SendPacket(&ResponsePacket, sizeof(ResponsePacket), NULL);
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.h b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.h
index 5bc5c8358..27d1a947d 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.h
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.h
@@ -70,6 +70,7 @@
#define BT_INFORMATION_NOTSUPPORTED 0x0001
#define BT_CONNECTION_SUCCESSFUL 0x0000
+ #define BT_CONNECTION_REFUSED_PSM 0x0002
#define BT_CONNECTION_REFUSED_RESOURCES 0x0004
#define BT_CONFIGURATION_SUCCESSFUL 0x0000
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h
index 564a2ba3e..88cc02035 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h
@@ -127,6 +127,7 @@
bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress);
void Bluetooth_ConnectionComplete(void);
void Bluetooth_DisconnectionComplete(void);
+ bool Bluetooth_ChannelConnectionRequest(uint16_t PSM);
void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t* Channel);
Bluetooth_Channel_t* Bluetooth_GetChannelData(uint16_t ChannelNumber, bool SearchByRemoteChannel);
Bluetooth_Channel_t* Bluetooth_OpenChannel(uint16_t PSM);