Add start of RFCOMM service layer to the incomplete BluetoothHost demo.

Reduce the size of the attribute search list from 15 ranges to 8 to save RAM.
pull/1469/head
Dean Camera 15 years ago
parent 5144ea76f6
commit 008e0e2e0a

@ -260,7 +260,7 @@ void Bluetooth_DisconnectionComplete(void)
* the user application must indicate if the channel connection should be rejected or not, based on the * the user application must indicate if the channel connection should be rejected or not, based on the
* protocol (PSM) value of the requested channel. * protocol (PSM) value of the requested channel.
* *
* \param PSM Protocol PSM value for the requested channel * \param[in] PSM Protocol PSM value for the requested channel
* *
* \return Boolean true to accept the channel connection request, false to reject it * \return Boolean true to accept the channel connection request, false to reject it
*/ */
@ -285,6 +285,10 @@ void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t*
/* Service Discovery Protocol packet */ /* Service Discovery Protocol packet */
SDP_ProcessPacket(Data, Channel); SDP_ProcessPacket(Data, Channel);
break; break;
case CHANNEL_PSM_RFCOMM:
/* RFCOMM (Serial Port) Protocol packet */
RFCOMM_ProcessPacket(Data, Channel);
break;
default: default:
/* Unknown Protocol packet */ /* Unknown Protocol packet */
printf_P(PSTR("Packet Received (Channel 0x%04X, PSM: 0x%02x):\r\n"), Channel->LocalNumber, Channel->PSM); printf_P(PSTR("Packet Received (Channel 0x%04X, PSM: 0x%02x):\r\n"), Channel->LocalNumber, Channel->PSM);

@ -45,6 +45,7 @@
#include <stdio.h> #include <stdio.h>
#include "Lib/ServiceDiscoveryProtocol.h" #include "Lib/ServiceDiscoveryProtocol.h"
#include "Lib/RFCOMM.h"
#include "Lib/BluetoothStack.h" #include "Lib/BluetoothStack.h"
#include "DeviceDescriptor.h" #include "DeviceDescriptor.h"

@ -95,12 +95,12 @@
*/ */
typedef struct typedef struct
{ {
uint8_t State; uint8_t State; /**< Current channel state, a value from the \ref BT_ChannelStates_t enum. */
uint16_t LocalNumber; uint16_t LocalNumber; /**< Local channel number on the device. */
uint16_t RemoteNumber; uint16_t RemoteNumber; /**< Remote channel number on the connected device. */
uint16_t PSM; uint16_t PSM; /**< Protocol used on the channel. */
uint16_t LocalMTU; uint16_t LocalMTU; /**< MTU of data sent from the connected device to the local device. */
uint16_t RemoteMTU; uint16_t RemoteMTU; /**< MTU of data sent from the local device to the connected device. */
} Bluetooth_Channel_t; } Bluetooth_Channel_t;
/** Type define for a Bluetooth device connection information structure. This structure contains all the /** Type define for a Bluetooth device connection information structure. This structure contains all the

@ -0,0 +1,36 @@
/*
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 "RFCOMM.h"
void RFCOMM_ProcessPacket(void* Data, Bluetooth_Channel_t* const Channel)
{
BT_RFCOMM_DEBUG(1, "PACKET RECEIVED");
}

@ -0,0 +1,57 @@
/*
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.
*/
/** \file
*
* Header file for RFCOMM.c.
*/
#ifndef _RFCOMM_H_
#define _RFCOMM_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_RFCOMM_DEBUG(l, s, ...) do { if (RFCOMM_DEBUG_LEVEL >= l) printf_P(PSTR("(RFCOMM) " s "\r\n"), ##__VA_ARGS__); } while (0)
#define RFCOMM_DEBUG_LEVEL 2
/* Function Prototypes: */
void RFCOMM_ProcessPacket(void* Data, Bluetooth_Channel_t* const Channel);
#endif

@ -119,11 +119,10 @@ static void SDP_ProcessServiceSearch(const SDP_PDUHeader_t* const SDPHeader, Blu
/* Copy over the service record handle to the response list */ /* Copy over the service record handle to the response list */
uint8_t AttrHeaderSize; uint8_t AttrHeaderSize;
SDP_GetLocalAttributeContainerSize(AttributeValue, &AttrHeaderSize); uint8_t AttrSize = SDP_GetLocalAttributeContainerSize(AttributeValue, &AttrHeaderSize);
memcpy_P(CurrResponsePos, AttributeValue + AttrHeaderSize, sizeof(uint32_t)); memcpy_P(CurrResponsePos, AttributeValue + AttrHeaderSize, AttrSize);
CurrResponsePos += AttrHeaderSize + sizeof(uint32_t); CurrResponsePos += AttrHeaderSize + AttrSize;
/* Increment the total number of service records added to the list */
AddedServiceHandles++; AddedServiceHandles++;
} }
@ -172,7 +171,7 @@ static void SDP_ProcessServiceAttribute(const SDP_PDUHeader_t* const SDPHeader,
BT_SDP_DEBUG(2, "-- Max Return Attribute Bytes: 0x%04X", MaxAttributeSize); BT_SDP_DEBUG(2, "-- Max Return Attribute Bytes: 0x%04X", MaxAttributeSize);
/* Retrieve the list of Attributes from the request */ /* Retrieve the list of Attributes from the request */
uint16_t AttributeList[15][2]; uint16_t AttributeList[8][2];
uint8_t TotalAttributes = SDP_GetAttributeList(AttributeList, &CurrentParameter); uint8_t TotalAttributes = SDP_GetAttributeList(AttributeList, &CurrentParameter);
BT_SDP_DEBUG(2, "-- Total Attributes: %d", TotalAttributes); BT_SDP_DEBUG(2, "-- Total Attributes: %d", TotalAttributes);
@ -263,7 +262,7 @@ static void SDP_ProcessServiceSearchAttribute(const SDP_PDUHeader_t* const SDPHe
BT_SDP_DEBUG(2, "-- Max Return Attribute Bytes: 0x%04X", MaxAttributeSize); BT_SDP_DEBUG(2, "-- Max Return Attribute Bytes: 0x%04X", MaxAttributeSize);
/* Retrieve the list of Attributes from the request */ /* Retrieve the list of Attributes from the request */
uint16_t AttributeList[15][2]; uint16_t AttributeList[8][2];
uint8_t TotalAttributes = SDP_GetAttributeList(AttributeList, &CurrentParameter); uint8_t TotalAttributes = SDP_GetAttributeList(AttributeList, &CurrentParameter);
BT_SDP_DEBUG(2, "-- Total Attributes: %d", TotalAttributes); BT_SDP_DEBUG(2, "-- Total Attributes: %d", TotalAttributes);

@ -60,6 +60,12 @@
#define SDP_PDU_SERVICESEARCHATTRIBUTEREQUEST 0x06 #define SDP_PDU_SERVICESEARCHATTRIBUTEREQUEST 0x06
#define SDP_PDU_SERVICESEARCHATTRIBUTERESPONSE 0x07 #define SDP_PDU_SERVICESEARCHATTRIBUTERESPONSE 0x07
/** Convenience macro - read a pointer out of PROGMEM space.
*
* \param[in] x Address of the pointer to read
*
* \return Pointer retrieved from PROGMEM space
*/
#define pgm_read_ptr(x) (void*)pgm_read_word(x) #define pgm_read_ptr(x) (void*)pgm_read_word(x)
/* Enums: */ /* Enums: */

@ -137,6 +137,7 @@ SRC = $(TARGET).c \
Lib/BluetoothACLPackets.c \ Lib/BluetoothACLPackets.c \
Lib/ServiceDiscoveryProtocol.c \ Lib/ServiceDiscoveryProtocol.c \
Lib/SDPServices.c \ Lib/SDPServices.c \
Lib/RFCOMM.c \
$(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c \ $(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c \
$(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c \ $(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c \
$(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save