projects
/
pub
/
USBasp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Make XPLAINBridge serial bridge much more reliable for the reception of characters...
[pub/USBasp.git]
/
Demos
/
Host
/
Incomplete
/
BluetoothHost
/
Lib
/
BluetoothACLPackets.c
diff --git
a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c
b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c
index
818caac
..
ec85aab
100644
(file)
--- a/
Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c
+++ b/
Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c
@@
-28,11
+28,17
@@
this software.
*/
this software.
*/
+/** \file
+ *
+ * Bluetooth L2CAP layer management code. This module managed the creation,
+ * configuration and teardown of L2CAP channels, and manages packet reception
+ * and sending to and from other Bluetooth devices.
+ */
+
/*
TODO: Make SendPacket respect receiver's MTU
TODO: Make ReceivePacket stitch together MTU fragments (?)
TODO: Add channel opened/closed callbacks
/*
TODO: Make SendPacket respect receiver's MTU
TODO: Make ReceivePacket stitch together MTU fragments (?)
TODO: Add channel opened/closed callbacks
- TODO: Figure out why delay is needed in connection for services
*/
#define INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C
*/
#define INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C
@@
-56,11
+62,11
@@
void Bluetooth_ACLTask(void)
/* Check if we are in a channel state which requires a configuration request to be sent */
switch (ChannelData->State)
{
/* Check if we are in a channel state which requires a configuration request to be sent */
switch (ChannelData->State)
{
- case Channel_Config_WaitConfig:
- ChannelData->State = Channel_Config_WaitReqResp;
+ case
BT_
Channel_Config_WaitConfig:
+ ChannelData->State =
BT_
Channel_Config_WaitReqResp;
break;
break;
- case Channel_Config_WaitSendConfig:
- ChannelData->State = Channel_Config_WaitResp;
+ case
BT_
Channel_Config_WaitSendConfig:
+ ChannelData->State =
BT_
Channel_Config_WaitResp;
break;
default:
MustSendConfigReq = false;
break;
default:
MustSendConfigReq = false;
@@
-218,7
+224,7
@@
uint8_t Bluetooth_SendPacket(void* Data, const uint16_t DataLen, Bluetooth_Chann
return BT_SENDPACKET_NotConnected;
/* If the destination channel is not the signalling channel and it is not currently fully open, abort */
return BT_SENDPACKET_NotConnected;
/* If the destination channel is not the signalling channel and it is not currently fully open, abort */
- if ((Channel != NULL) && (Channel->State != Channel_Open))
+ if ((Channel != NULL) && (Channel->State !=
BT_
Channel_Open))
return BT_SENDPACKET_ChannelNotOpen;
/* Fill out the packet's header from the remote device connection information structure */
return BT_SENDPACKET_ChannelNotOpen;
/* Fill out the packet's header from the remote device connection information structure */
@@
-228,8
+234,10
@@
uint8_t Bluetooth_SendPacket(void* Data, const uint16_t DataLen, Bluetooth_Chann
DataHeader.DestinationChannel = (Channel == NULL) ? BT_CHANNEL_SIGNALING : Channel->RemoteNumber;
Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);
DataHeader.DestinationChannel = (Channel == NULL) ? BT_CHANNEL_SIGNALING : Channel->RemoteNumber;
Pipe_SelectPipe(BLUETOOTH_DATA_OUT_PIPE);
+
+ Pipe_WaitUntilReady();
Pipe_Unfreeze();
Pipe_Unfreeze();
-
+
/* Write the packet contents to the pipe so that it can be sent to the remote device */
Pipe_Write_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));
Pipe_Write_Stream_LE(&DataHeader, sizeof(DataHeader));
/* Write the packet contents to the pipe so that it can be sent to the remote device */
Pipe_Write_Stream_LE(&ACLPacketHeader, sizeof(ACLPacketHeader));
Pipe_Write_Stream_LE(&DataHeader, sizeof(DataHeader));
@@
-248,7
+256,7
@@
uint8_t Bluetooth_SendPacket(void* Data, const uint16_t DataLen, Bluetooth_Chann
return BT_SENDPACKET_NoError;
}
return BT_SENDPACKET_NoError;
}
-/** Opens a
b
luetooth channel to the currently connected remote device, so that data can be exchanged.
+/** Opens a
B
luetooth channel to the currently connected remote device, so that data can be exchanged.
*
* \note The channel is not immediately opened when this function returns - it must undergo a two way
* connection and configuration process first as the main Bluetooth stack processing task is
*
* \note The channel is not immediately opened when this function returns - it must undergo a two way
* connection and configuration process first as the main Bluetooth stack processing task is
@@
-266,7
+274,7
@@
Bluetooth_Channel_t* Bluetooth_OpenChannel(const uint16_t PSM)
/* Search through the channel information list for a free channel item */
for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)
{
/* Search through the channel information list for a free channel item */
for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)
{
- if (Bluetooth_Connection.Channels[i].State == Channel_Closed)
+ if (Bluetooth_Connection.Channels[i].State ==
BT_
Channel_Closed)
{
ChannelData = &Bluetooth_Connection.Channels[i];
{
ChannelData = &Bluetooth_Connection.Channels[i];
@@
-285,7
+293,7
@@
Bluetooth_Channel_t* Bluetooth_OpenChannel(const uint16_t PSM)
ChannelData->RemoteNumber = 0;
ChannelData->PSM = PSM;
ChannelData->LocalMTU = MAXIMUM_CHANNEL_MTU;
ChannelData->RemoteNumber = 0;
ChannelData->PSM = PSM;
ChannelData->LocalMTU = MAXIMUM_CHANNEL_MTU;
- ChannelData->State = Channel_WaitConnectRsp;
+ ChannelData->State =
BT_
Channel_WaitConnectRsp;
struct
{
struct
{
@@
-311,7
+319,7
@@
Bluetooth_Channel_t* Bluetooth_OpenChannel(const uint16_t PSM)
return ChannelData;
}
return ChannelData;
}
-/** Closes a
b
luetooth channel that is open to the currently connected remote device, so that no further data
+/** Closes a
B
luetooth channel that is open to the currently connected remote device, so that no further data
* can be exchanged.
*
* \note The channel is not immediately closed when this function returns - it must undergo an asynchronous
* can be exchanged.
*
* \note The channel is not immediately closed when this function returns - it must undergo an asynchronous
@@
-324,11
+332,11
@@
Bluetooth_Channel_t* Bluetooth_OpenChannel(const uint16_t PSM)
void Bluetooth_CloseChannel(Bluetooth_Channel_t* const Channel)
{
/* Don't try to close a non-existing or already closed channel */
void Bluetooth_CloseChannel(Bluetooth_Channel_t* const Channel)
{
/* Don't try to close a non-existing or already closed channel */
- if ((Channel == NULL) || (Channel->State == Channel_Closed))
+ if ((Channel == NULL) || (Channel->State ==
BT_
Channel_Closed))
return;
/* Set the channel's state to the start of the teardown process */
return;
/* Set the channel's state to the start of the teardown process */
- Channel->State = Channel_WaitDisconnect;
+ Channel->State =
BT_
Channel_WaitDisconnect;
struct
{
struct
{
@@
-369,8
+377,6
@@
static inline void Bluetooth_Signal_ConnectionReq(const BT_Signal_Header_t* cons
BT_ACL_DEBUG(2, "-- PSM: 0x%04X", ConnectionRequest.PSM);
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", ConnectionRequest.SourceChannel);
BT_ACL_DEBUG(2, "-- PSM: 0x%04X", ConnectionRequest.PSM);
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", ConnectionRequest.SourceChannel);
- _delay_ms(15); // TODO - Determine why this is needed
-
/* Try to retrieve the existing channel's information structure if it exists */
Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConnectionRequest.SourceChannel, CHANNEL_SEARCH_REMOTENUMBER);
/* Try to retrieve the existing channel's information structure if it exists */
Bluetooth_Channel_t* ChannelData = Bluetooth_GetChannelData(ConnectionRequest.SourceChannel, CHANNEL_SEARCH_REMOTENUMBER);
@@
-380,7
+386,7
@@
static inline void Bluetooth_Signal_ConnectionReq(const BT_Signal_Header_t* cons
/* Look through the channel information list for a free entry */
for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)
{
/* Look through the channel information list for a free entry */
for (uint8_t i = 0; i < BLUETOOTH_MAX_OPEN_CHANNELS; i++)
{
- if (Bluetooth_Connection.Channels[i].State == Channel_Closed)
+ if (Bluetooth_Connection.Channels[i].State ==
BT_
Channel_Closed)
{
ChannelData = &Bluetooth_Connection.Channels[i];
{
ChannelData = &Bluetooth_Connection.Channels[i];
@@
-403,7
+409,7
@@
static inline void Bluetooth_Signal_ConnectionReq(const BT_Signal_Header_t* cons
ChannelData->RemoteNumber = ConnectionRequest.SourceChannel;
ChannelData->PSM = ConnectionRequest.PSM;
ChannelData->LocalMTU = MAXIMUM_CHANNEL_MTU;
ChannelData->RemoteNumber = ConnectionRequest.SourceChannel;
ChannelData->PSM = ConnectionRequest.PSM;
ChannelData->LocalMTU = MAXIMUM_CHANNEL_MTU;
- ChannelData->State = Channel_Config_WaitConfig;
+ ChannelData->State =
BT_
Channel_Config_WaitConfig;
ChannelStatus = BT_CONNECTION_SUCCESSFUL;
}
ChannelStatus = BT_CONNECTION_SUCCESSFUL;
}
@@
-465,7
+471,7
@@
static inline void Bluetooth_Signal_ConnectionResp(const BT_Signal_Header_t* con
/* Set the channel structure's remote channel number to the channel allocated on the remote device */
ChannelData->RemoteNumber = ConnectionResponse.SourceChannel;
ChannelData->State = (ConnectionResponse.Result == BT_CONNECTION_SUCCESSFUL) ?
/* Set the channel structure's remote channel number to the channel allocated on the remote device */
ChannelData->RemoteNumber = ConnectionResponse.SourceChannel;
ChannelData->State = (ConnectionResponse.Result == BT_CONNECTION_SUCCESSFUL) ?
-
Channel_Config_WaitConfig :
Channel_Closed;
+
BT_Channel_Config_WaitConfig : BT_
Channel_Closed;
}
}
}
}
@@
-538,14
+544,14
@@
static inline void Bluetooth_Signal_ConfigurationReq(const BT_Signal_Header_t* c
{
switch (ChannelData->State)
{
{
switch (ChannelData->State)
{
- case Channel_Config_WaitConfig:
- ChannelData->State = Channel_Config_WaitSendConfig;
+ case
BT_
Channel_Config_WaitConfig:
+ ChannelData->State =
BT_
Channel_Config_WaitSendConfig;
break;
break;
- case Channel_Config_WaitReqResp:
- ChannelData->State = Channel_Config_WaitResp;
+ case
BT_
Channel_Config_WaitReqResp:
+ ChannelData->State =
BT_
Channel_Config_WaitResp;
break;
break;
- case Channel_Config_WaitReq:
- ChannelData->State = Channel_Open;
+ case
BT_
Channel_Config_WaitReq:
+ ChannelData->State =
BT_
Channel_Open;
break;
}
}
break;
}
}
@@
-583,18
+589,18
@@
static inline void Bluetooth_Signal_ConfigurationResp(const BT_Signal_Header_t*
{
switch (ChannelData->State)
{
{
switch (ChannelData->State)
{
- case Channel_Config_WaitReqResp:
- ChannelData->State = Channel_Config_WaitReq;
+ case
BT_
Channel_Config_WaitReqResp:
+ ChannelData->State =
BT_
Channel_Config_WaitReq;
break;
break;
- case Channel_Config_WaitResp:
- ChannelData->State = Channel_Open;
+ case
BT_
Channel_Config_WaitResp:
+ ChannelData->State =
BT_
Channel_Open;
break;
}
}
else
{
/* Configuration failed - close the channel */
break;
}
}
else
{
/* Configuration failed - close the channel */
- ChannelData->State = Channel_Closed;
+ ChannelData->State =
BT_
Channel_Closed;
}
}
}
}
}
}
@@
-638,7
+644,7
@@
static inline void Bluetooth_Signal_DisconnectionReq(const BT_Signal_Header_t* c
/* If the channel was found in the channel list, close it */
if (ChannelData != NULL)
/* If the channel was found in the channel list, close it */
if (ChannelData != NULL)
- ChannelData->State = Channel_Closed;
+ ChannelData->State =
BT_
Channel_Closed;
BT_ACL_DEBUG(1, ">> L2CAP Disconnection Response");
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", ResponsePacket.DisconnectionResponse.SourceChannel);
BT_ACL_DEBUG(1, ">> L2CAP Disconnection Response");
BT_ACL_DEBUG(2, "-- Source Channel: 0x%04X", ResponsePacket.DisconnectionResponse.SourceChannel);
@@
-667,7
+673,7
@@
static inline void Bluetooth_Signal_DisconnectionResp(const BT_Signal_Header_t*
/* If the channel was found in the channel list, close it */
if (ChannelData != NULL)
/* If the channel was found in the channel list, close it */
if (ChannelData != NULL)
- ChannelData->State = Channel_Closed;
+ ChannelData->State =
BT_
Channel_Closed;
}
/** Internal Bluetooth stack Signal Command processing routine for an Echo Request command.
}
/** Internal Bluetooth stack Signal Command processing routine for an Echo Request command.