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 14 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
* 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);

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

@ -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

@ -113,7 +113,7 @@ const struct
{(SDP_DATATYPE_UnsignedInt | SDP_DATASIZE_16Bit), SWAPENDIAN_16(0x0100)},
}
}
};
};
const struct
{

@ -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);

@ -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: */

@ -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 \

File diff suppressed because one or more lines are too long

@ -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);

Loading…
Cancel
Save