Skip to content
Snippets Groups Projects
Commit e55f3386 authored by Dean Camera's avatar Dean Camera
Browse files

Document the Bluetooth ACL layer. Remove unneeded parameters from the...

Document the Bluetooth ACL layer. Remove unneeded parameters from the signalling command processing routines.

Change over the code so that the bluetooth packet data is read in by the stack rather than the user application, to make it more unform for sending/receiving, and so the library can handle incomming fragmentation in the future.

Start Service Discovery Protocol decoding and processing.
parent 882ef0c9
No related branches found
No related tags found
No related merge requests found
Showing
with 362 additions and 128 deletions
......@@ -241,18 +241,25 @@ void Bluetooth_DisconnectionComplete(void)
/** 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.
*
* \param PacketLength Length of the packet data, in bytes - this must be decremented as data is read
* \param Channel Bluetooth ACL data channel information structure for the packet's destination channel
* \param Data Pointer to a buffer where the received data is stored
* \param DataLen Length of the packet data, in bytes
* \param Channel Bluetooth ACL data channel information structure for the packet's destination channel
*/
void Bluetooth_PacketReceived(uint16_t* PacketLength, Bluetooth_Channel_t* Channel)
void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t* Channel)
{
uint8_t DataPayload[*PacketLength];
Pipe_Read_Stream_LE(&DataPayload, *PacketLength);
*PacketLength = 0;
printf_P(PSTR("Packet Received (Channel 0x%04X, PSM: 0x%02x):\r\n"), Channel->LocalNumber, Channel->PSM);
for (uint16_t Byte = 0; Byte < sizeof(DataPayload); Byte++)
printf_P(PSTR("0x%02X "), DataPayload[Byte]);
puts_P(PSTR("\r\n"));
switch (Channel->PSM)
{
case CHANNEL_PSM_SDP:
/* Service Discovery Protocol packet */
ServiceDiscovery_ProcessPacket(Data, DataLen, Channel);
break;
default:
/* Unknown Protocol packet */
printf_P(PSTR("Packet Received (Channel 0x%04X, PSM: 0x%02x):\r\n"), Channel->LocalNumber, Channel->PSM);
for (uint16_t Byte = 0; Byte < DataLen; Byte++)
printf_P(PSTR("0x%02X "), ((uint8_t*)Data)[Byte]);
puts_P(PSTR("\r\n"));
break;
}
}
......@@ -43,6 +43,7 @@
#include <avr/power.h>
#include <stdio.h>
#include "Lib/ServiceDiscoveryProtocol.h"
#include "Lib/BluetoothStack.h"
#include "DeviceDescriptor.h"
......
......@@ -35,14 +35,16 @@
#include <avr/io.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Peripheral/SerialStream.h>
#include "BluetoothStack.h"
/* Macros: */
#define BT_ACL_DEBUG(l, s, ...) do { if (ACL_DEBUG_LEVEL >= l) printf_P(PSTR("(ACL) " s "\r\n"), __VA_ARGS__); } while (0)
#define ACL_DEBUG_LEVEL 2
#define ACL_DEBUG_LEVEL 0
#define BT_CHANNELNUMBER_BASEOFFSET 0x0040
......@@ -158,32 +160,16 @@
void Bluetooth_ACLTask(void);
#if defined(INCLUDE_FROM_BLUETOOTH_ACLPACKETS_C)
static void Bluetooth_ProcessACLPackets(void);
static inline void Bluetooth_Signal_ConnectionReq(BT_ACL_Header_t* ACLPacketHeader,
BT_DataPacket_Header_t* DataHeader,
BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_ConnectionResp(BT_ACL_Header_t* ACLPacketHeader,
BT_DataPacket_Header_t* DataHeader,
BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_EchoReq(BT_ACL_Header_t* ACLPacketHeader,
BT_DataPacket_Header_t* DataHeader,
BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_ConfigurationReq(BT_ACL_Header_t* ACLPacketHeader,
BT_DataPacket_Header_t* DataHeader,
BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_ConfigurationResp(BT_ACL_Header_t* ACLPacketHeader,
BT_DataPacket_Header_t* DataHeader,
BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_DisconnectionReq(BT_ACL_Header_t* ACLPacketHeader,
BT_DataPacket_Header_t* DataHeader,
BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_DisconnectionResp(BT_ACL_Header_t* ACLPacketHeader,
BT_DataPacket_Header_t* DataHeader,
BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_InformationReq(BT_ACL_Header_t* ACLPacketHeader,
BT_DataPacket_Header_t* DataHeader,
BT_Signal_Header_t* SignalCommandHeader);
static void Bluetooth_ProcessIncommingACLPackets(void);
static inline void Bluetooth_Signal_ConnectionReq(BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_ConnectionResp(BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_ConfigurationReq(BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_ConfigurationResp(BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_DisconnectionReq(BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_DisconnectionResp(BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_EchoReq(BT_Signal_Header_t* SignalCommandHeader);
static inline void Bluetooth_Signal_InformationReq(BT_Signal_Header_t* SignalCommandHeader);
#endif
#endif
......@@ -35,15 +35,17 @@
#include <avr/io.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Peripheral/SerialStream.h>
#include "BluetoothStack.h"
#include "BluetoothClassCodes.h"
/* Macros: */
#define BT_HCI_DEBUG(l, s, ...) do { if (HCI_DEBUG_LEVEL >= l) printf_P(PSTR("(HCI) " s "\r\n"), __VA_ARGS__); } while (0)
#define HCI_DEBUG_LEVEL 1
#define HCI_DEBUG_LEVEL 0
#define OGF_LINK_CONTROL 0x01
#define OGF_CTRLR_BASEBAND 0x03
......
......@@ -34,26 +34,24 @@
/* Includes: */
#include <LUFA/Drivers/USB/USB.h>
#include "BluetoothHost.h"
/* Macros: */
#define BLUETOOTH_DATA_IN_PIPE 1
#define BLUETOOTH_DATA_OUT_PIPE 2
#define BLUETOOTH_EVENTS_PIPE 3
#define BLUETOOTH_DATA_IN_PIPE 1
#define BLUETOOTH_DATA_OUT_PIPE 2
#define BLUETOOTH_EVENTS_PIPE 3
#define BLUETOOTH_MAX_OPEN_CHANNELS 6
#define BLUETOOTH_MAX_OPEN_CHANNELS 6
#define CHANNEL_PSM_SERVICEDISCOVERY 0x0001
#define CHANNEL_PSM_UDP 0x0002
#define CHANNEL_PSM_RFCOMM 0x0003
#define CHANNEL_PSM_TCP 0x0004
#define CHANNEL_PSM_IP 0x0009
#define CHANNEL_PSM_FTP 0x000A
#define CHANNEL_PSM_HTTP 0x000C
#define CHANNEL_PSM_UPNP 0x0010
#define CHANNEL_PSM_HIDP 0x0011
#define CHANNEL_PSM_SDP 0x0001
#define CHANNEL_PSM_UDP 0x0002
#define CHANNEL_PSM_RFCOMM 0x0003
#define CHANNEL_PSM_TCP 0x0004
#define CHANNEL_PSM_IP 0x0009
#define CHANNEL_PSM_FTP 0x000A
#define CHANNEL_PSM_HTTP 0x000C
#define CHANNEL_PSM_UPNP 0x0010
#define CHANNEL_PSM_HIDP 0x0011
#define MAXIMUM_CHANNEL_MTU 255
#define MAXIMUM_CHANNEL_MTU 255
/* Enums: */
/** Enum for the possible states for a bluetooth ACL channel. */
......@@ -101,19 +99,21 @@
*/
typedef struct
{
bool IsConnected;
uint16_t ConnectionHandle;
uint8_t RemoteAddress[6];
Bluetooth_Channel_t Channels[BLUETOOTH_MAX_OPEN_CHANNELS];
uint8_t SignallingIdentifier;
bool IsConnected; /**< Indicates if the stack is currently connected to a remote device - if this value is
* false, the remaining elements are invalid.
*/
uint16_t ConnectionHandle; /**< Connection handle to the remote device, used internally in the stack. */
uint8_t RemoteAddress[6]; /**< Bluetooth device address of the attached remote device. */
Bluetooth_Channel_t Channels[BLUETOOTH_MAX_OPEN_CHANNELS]; /**< Channel information structures for the connection. */
uint8_t SignallingIdentifier; /**< Next Signalling Channel unique command sequence identifier. */
} Bluetooth_Connection_t;
/** Local Bluetooth device information structure, for the defining of local device characteristics for the Bluetooth stack. */
typedef struct
{
uint32_t Class;
char PINCode[16];
char Name[];
uint32_t Class; /**< Class of the local device, a mask of DEVICE_CLASS_* masks. */
char PINCode[16]; /**< Pin code required to send or receive in order to authenticate with a remote device. */
char Name[]; /**< Name of the local bluetooth device, up to 248 characters. */
} Bluetooth_Device_t;
/* Includes: */
......@@ -127,7 +127,7 @@
bool Bluetooth_ConnectionRequest(uint8_t* RemoteAddress);
void Bluetooth_ConnectionComplete(void);
void Bluetooth_DisconnectionComplete(void);
void Bluetooth_PacketReceived(uint16_t* PacketLength, Bluetooth_Channel_t* Channel);
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);
void Bluetooth_CloseChannel(Bluetooth_Channel_t* Channel);
......
/*
LUFA Library
Copyright (C) Dean Camera, 2010.
dean [at] fourwalledcubicle [dot] com
www.fourwalledcubicle.com
*/
/*
Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
#include "ServiceDiscoveryProtocol.h"
void ServiceDiscovery_ProcessPacket(void* Data, uint16_t Length, Bluetooth_Channel_t* Channel)
{
SDP_PDUHeader_t* SDPHeader = (SDP_PDUHeader_t*)Data;
SDPHeader->ParameterLength = SwapEndian_16(SDPHeader->ParameterLength);
BT_SDP_DEBUG(1, "<< Service Discovery Packet", NULL);
BT_SDP_DEBUG(2, "-- PDU ID: 0x%02X", SDPHeader->PDU);
BT_SDP_DEBUG(2, "-- Param Length: 0x%04X", SDPHeader->ParameterLength);
}
/*
LUFA Library
Copyright (C) Dean Camera, 2010.
dean [at] fourwalledcubicle [dot] com
www.fourwalledcubicle.com
*/
/*
Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
#ifndef _SERVICEDISCOVERYPROTOCOL_H_
#define _SERVICEDISCOVERYPROTOCOL_H_
/* Includes: */
#include <avr/io.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include <LUFA/Common/Common.h>
#include <LUFA/Drivers/Peripheral/SerialStream.h>
#include "BluetoothStack.h"
/* Macros: */
#define BT_SDP_DEBUG(l, s, ...) do { if (SDP_DEBUG_LEVEL >= l) printf_P(PSTR("(SDP) " s "\r\n"), __VA_ARGS__); } while (0)
#define SDP_DEBUG_LEVEL 2
#define SDP_PDU_ERRORRESPONSE 0x01
#define SDP_PDU_SERVICESEARCHREQUEST 0x02
#define SDP_PDU_SERVICESEARCHRESPONSE 0x03
#define SDP_PDU_SERVICEATTRIBUTEREQUEST 0x04
#define SDP_PDU_SERVICEATTRIBUTERESPONSE 0x05
#define SDP_PDU_SERVICESEARCHATTRIBUTEREQUEST 0x06
#define SDP_PDU_SERVICESEARCHATTRIBUTERESPONSE 0x07
/* Type Defines: */
typedef struct
{
uint8_t PDU;
uint16_t TransactionID;
uint16_t ParameterLength;
} SDP_PDUHeader_t;
/* Function Prototypes: */
void ServiceDiscovery_ProcessPacket(void* Data, uint16_t Length, Bluetooth_Channel_t* Channel);
#endif
......@@ -135,6 +135,7 @@ SRC = $(TARGET).c \
Lib/BluetoothStack.c \
Lib/BluetoothHCICommands.c \
Lib/BluetoothACLPackets.c \
Lib/ServiceDiscoveryProtocol.c \
$(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c \
$(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \
......
This diff is collapsed.
......@@ -155,7 +155,7 @@
* Board directory should be included instead.
*
* \dir LUFA/Drivers/Board/JMDBU2
* \briefJM-DB-U2 board hardware driver files.
* \brief JM-DB-U2 board hardware driver files.
*
* This folder contains drivers for hardware on the JM-DB-U2 boards (http://u2.mattair.net/). The header files in this folder
* should not be included directly in user applications; the similarly named dispatch header files located in the parent Board
......
......@@ -113,7 +113,7 @@ int main(void)
/* Read in next LED colour command from the host */
uint8_t ColorUpdate = fgetc(&USBSerialStream);
/* Top 3 bits select the LED, bottom three control the brightness */
/* Top 3 bits select the LED, bottom 5 control the brightness */
uint8_t Channel = (ColorUpdate & 0b11100000);
uint8_t Duty = (ColorUpdate & 0b00011111);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment