3      Copyright (C) Dean Camera, 2010. 
   5   dean [at] fourwalledcubicle [dot] com 
   6       www.fourwalledcubicle.com 
  10   Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, distribute, and sell this  
  13   software and its documentation for any purpose is hereby granted 
  14   without fee, provided that the above copyright notice appear in  
  15   all copies and that both that the copyright notice and this 
  16   permission notice and warranty disclaimer appear in supporting  
  17   documentation, and that the name of the author not be used in  
  18   advertising or publicity pertaining to distribution of the  
  19   software without specific, written prior permission. 
  21   The author disclaim all warranties with regard to this 
  22   software, including all implied warranties of merchantability 
  23   and fitness.  In no event shall the author be liable for any 
  24   special, indirect or consequential damages or any damages 
  25   whatsoever resulting from loss of use, data or profits, whether 
  26   in an action of contract, negligence or other tortious action, 
  27   arising out of or in connection with the use or performance of 
  31 #include "BluetoothStack.h" 
  33 /** Bluetooth device connection information structure. Once connected to a remote device, this structure tracks the 
  34  *  connection state of the individual L2CAP channels. 
  36 Bluetooth_Connection_t Bluetooth_Connection 
= {IsConnected
: false}; 
  38 /** Bluetooth configuration structure. This structure configures the bluetooth stack's user alterable settings. */ 
  39 Bluetooth_Device_t Bluetooth_DeviceConfiguration 
= 
  41                 Class
:   (DEVICE_CLASS_SERVICE_CAPTURING 
| DEVICE_CLASS_MAJOR_COMPUTER 
| DEVICE_CLASS_MINOR_COMPUTER_PALM
), 
  43                 Name
:    "LUFA Bluetooth Demo" 
  46 void Bluetooth_Stack_Init(void) 
  48         Bluetooth_HCIProcessingState 
= Bluetooth_Init
; 
  51 void Bluetooth_Stack_USBTask(void) 
  53         Bluetooth_ProcessHCICommands(); 
  54         Bluetooth_ProcessACLPackets(); 
  57 Bluetooth_Channel_t
* Bluetooth_GetChannelData(uint16_t ChannelNumber
, bool SearchBySource
) 
  59         for (uint8_t i 
= 0; i 
< BLUETOOTH_MAX_OPEN_CHANNELS
; i
++) 
  61                 Bluetooth_Channel_t
* CurrentChannelStructure 
= &Bluetooth_Connection
.Channels
[i
]; 
  63                 uint16_t CurrentChannelNumber 
= (SearchBySource
) ? CurrentChannelStructure
->RemoteNumber 
: 
  64                                                                    CurrentChannelStructure
->LocalNumber
; 
  66                 if (CurrentChannelNumber 
== ChannelNumber
) 
  67                   return CurrentChannelStructure
; 
  73 Bluetooth_Channel_t
* Bluetooth_InitChannelData(uint16_t RemoteChannelNumber
, uint16_t PSM
) 
  75         for (uint8_t i 
= 0; i 
< BLUETOOTH_MAX_OPEN_CHANNELS
; i
++) 
  77                 Bluetooth_Channel_t
* CurrentChannelStructure 
= &Bluetooth_Connection
.Channels
[i
]; 
  79                 if (CurrentChannelStructure
->State 
== Channel_Closed
) 
  81                         CurrentChannelStructure
->RemoteNumber 
= RemoteChannelNumber
; 
  82                         CurrentChannelStructure
->LocalNumber  
= (BLUETOOTH_CHANNELNUMBER_BASEOFFSET 
+ i
); 
  83                         CurrentChannelStructure
->PSM          
= PSM
; 
  84                         CurrentChannelStructure
->State        
= Channel_Config
; 
  86                         return CurrentChannelStructure
;