From 008e0e2e0a13e64e03f27f1c9a008ef201560878 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Thu, 3 Jun 2010 03:58:57 +0000 Subject: [PATCH] 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. --- .../Incomplete/BluetoothHost/BluetoothHost.c | 6 +- .../Incomplete/BluetoothHost/BluetoothHost.h | 1 + .../BluetoothHost/Lib/BluetoothStack.h | 12 ++-- .../Incomplete/BluetoothHost/Lib/RFCOMM.c | 36 ++++++++++++ .../Incomplete/BluetoothHost/Lib/RFCOMM.h | 57 +++++++++++++++++++ .../BluetoothHost/Lib/SDPServices.c | 2 +- .../Lib/ServiceDiscoveryProtocol.c | 11 ++-- .../Lib/ServiceDiscoveryProtocol.h | 6 ++ Demos/Host/Incomplete/BluetoothHost/makefile | 1 + LUFA.pnproj | 2 +- Projects/AVRISP-MKII/AVRISP.c | 4 +- 11 files changed, 121 insertions(+), 17 deletions(-) create mode 100644 Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c create mode 100644 Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h diff --git a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c index b9b5ec14b1..737932cdbe 100644 --- a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c +++ b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c @@ -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 * 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 */ @@ -285,6 +285,10 @@ void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t* /* Service Discovery Protocol packet */ SDP_ProcessPacket(Data, Channel); break; + case CHANNEL_PSM_RFCOMM: + /* RFCOMM (Serial Port) Protocol packet */ + RFCOMM_ProcessPacket(Data, Channel); + break; default: /* Unknown Protocol packet */ printf_P(PSTR("Packet Received (Channel 0x%04X, PSM: 0x%02x):\r\n"), Channel->LocalNumber, Channel->PSM); diff --git a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.h b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.h index 266181db45..ce7d1f5008 100644 --- a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.h +++ b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.h @@ -45,6 +45,7 @@ #include #include "Lib/ServiceDiscoveryProtocol.h" + #include "Lib/RFCOMM.h" #include "Lib/BluetoothStack.h" #include "DeviceDescriptor.h" diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h index 4b16a8f48e..fb25ec77d4 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothStack.h @@ -95,12 +95,12 @@ */ typedef struct { - uint8_t State; - uint16_t LocalNumber; - uint16_t RemoteNumber; - uint16_t PSM; - uint16_t LocalMTU; - uint16_t RemoteMTU; + uint8_t State; /**< Current channel state, a value from the \ref BT_ChannelStates_t enum. */ + uint16_t LocalNumber; /**< Local channel number on the device. */ + uint16_t RemoteNumber; /**< Remote channel number on the connected device. */ + uint16_t PSM; /**< Protocol used on the channel. */ + uint16_t LocalMTU; /**< MTU of data sent from the connected device to the local device. */ + uint16_t RemoteMTU; /**< MTU of data sent from the local device to the connected device. */ } Bluetooth_Channel_t; /** Type define for a Bluetooth device connection information structure. This structure contains all the diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c new file mode 100644 index 0000000000..052bf3fdbe --- /dev/null +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.c @@ -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"); +} diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h new file mode 100644 index 0000000000..7f1b6269a9 --- /dev/null +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/RFCOMM.h @@ -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 + #include + #include + #include + + #include + #include + + #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 diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.c b/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.c index 908be0c6d5..d812252b1b 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.c @@ -113,7 +113,7 @@ const struct {(SDP_DATATYPE_UnsignedInt | SDP_DATASIZE_16Bit), SWAPENDIAN_16(0x0100)}, } } - }; + }; const struct { diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c index df0db3bed5..0ee0784c5c 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c @@ -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 */ uint8_t AttrHeaderSize; - SDP_GetLocalAttributeContainerSize(AttributeValue, &AttrHeaderSize); - memcpy_P(CurrResponsePos, AttributeValue + AttrHeaderSize, sizeof(uint32_t)); - CurrResponsePos += AttrHeaderSize + sizeof(uint32_t); + uint8_t AttrSize = SDP_GetLocalAttributeContainerSize(AttributeValue, &AttrHeaderSize); + memcpy_P(CurrResponsePos, AttributeValue + AttrHeaderSize, AttrSize); + CurrResponsePos += AttrHeaderSize + AttrSize; - /* Increment the total number of service records added to the list */ 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); /* 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); 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); /* 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); BT_SDP_DEBUG(2, "-- Total Attributes: %d", TotalAttributes); diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h index e46729cd97..dd5182c348 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h @@ -60,6 +60,12 @@ #define SDP_PDU_SERVICESEARCHATTRIBUTEREQUEST 0x06 #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) /* Enums: */ diff --git a/Demos/Host/Incomplete/BluetoothHost/makefile b/Demos/Host/Incomplete/BluetoothHost/makefile index 76571f8bda..8e3c55a7bd 100644 --- a/Demos/Host/Incomplete/BluetoothHost/makefile +++ b/Demos/Host/Incomplete/BluetoothHost/makefile @@ -137,6 +137,7 @@ SRC = $(TARGET).c \ Lib/BluetoothACLPackets.c \ Lib/ServiceDiscoveryProtocol.c \ Lib/SDPServices.c \ + Lib/RFCOMM.c \ $(LUFA_PATH)/LUFA/Drivers/Peripheral/SerialStream.c \ $(LUFA_PATH)/LUFA/Drivers/Peripheral/Serial.c \ $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c \ diff --git a/LUFA.pnproj b/LUFA.pnproj index 22c051037b..ee003d457e 100644 --- a/LUFA.pnproj +++ b/LUFA.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/Projects/AVRISP-MKII/AVRISP.c b/Projects/AVRISP-MKII/AVRISP.c index 81c1385c91..0766025c11 100644 --- a/Projects/AVRISP-MKII/AVRISP.c +++ b/Projects/AVRISP-MKII/AVRISP.c @@ -91,7 +91,7 @@ void EVENT_USB_Device_ConfigurationChanged(void) /* Setup AVRISP data Endpoints */ if (!(Endpoint_ConfigureEndpoint(AVRISP_DATA_OUT_EPNUM, EP_TYPE_BULK, - ENDPOINT_DIR_OUT, AVRISP_DATA_EPSIZE, + ENDPOINT_DIR_OUT, AVRISP_DATA_EPSIZE, ENDPOINT_BANK_SINGLE))) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); @@ -99,7 +99,7 @@ void EVENT_USB_Device_ConfigurationChanged(void) #if defined(LIBUSB_DRIVER_COMPAT) if (!(Endpoint_ConfigureEndpoint(AVRISP_DATA_IN_EPNUM, EP_TYPE_BULK, - ENDPOINT_DIR_IN, AVRISP_DATA_EPSIZE, + ENDPOINT_DIR_IN, AVRISP_DATA_EPSIZE, ENDPOINT_BANK_SINGLE))) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR);