Split out the RFCOMM Control Channel command processing code into a seperate set...
[pub/USBasp.git] / Demos / Host / Incomplete / BluetoothHost / Lib / RFCOMMControl.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 /** \file
32 *
33 * RFCOMM multiplexer control layer module. This module handles multiplexer
34 * channel commands to the control DLCI in the RFCOMM layer, to open, configure,
35 * test and close logical RFCOMM channels.
36 */
37
38 #define INCLUDE_FROM_RFCOMM_CONTROL_C
39 #include "RFCOMMControl.h"
40
41 void RFCOMM_ProcessControlCommand(const uint8_t* Command, Bluetooth_Channel_t* const Channel)
42 {
43 const RFCOMM_Command_t* CommandHeader = (const RFCOMM_Command_t*)Command;
44 const uint8_t* CommandData = (const uint8_t*)Command + sizeof(RFCOMM_Command_t);
45
46 switch (CommandHeader->Command)
47 {
48 case RFCOMM_Control_Test:
49 RFCOMM_ProcessTestCommand(CommandHeader, CommandData);
50 break;
51 case RFCOMM_Control_FlowControlEnable:
52 RFCOMM_ProcessFCECommand(CommandHeader, CommandData);
53 break;
54 case RFCOMM_Control_FlowControlDisable:
55 RFCOMM_ProcessFCDCommand(CommandHeader, CommandData);
56 break;
57 case RFCOMM_Control_ModemStatus:
58 RFCOMM_ProcessMSCommand(CommandHeader, CommandData);
59 break;
60 case RFCOMM_Control_RemotePortNegotiation:
61 RFCOMM_ProcessRPNCommand(CommandHeader, CommandData);
62 break;
63 case RFCOMM_Control_RemoteLineStatus:
64 RFCOMM_ProcessRLSCommand(CommandHeader, CommandData);
65 break;
66 case RFCOMM_Control_DLCParameterNegotiation:
67 RFCOMM_ProcessDPNCommand(CommandHeader, CommandData);
68 break;
69 default:
70 BT_RFCOMM_DEBUG(1, "<< Unknown Command");
71 break;
72 }
73 }
74
75 static void RFCOMM_ProcessTestCommand(const RFCOMM_Command_t* CommandHeader, const uint8_t* CommandData)
76 {
77 BT_RFCOMM_DEBUG(1, "<< TEST Command");
78 }
79
80 static void RFCOMM_ProcessFCECommand(const RFCOMM_Command_t* CommandHeader, const uint8_t* CommandData)
81 {
82 BT_RFCOMM_DEBUG(1, "<< FCE Command");
83 }
84
85 static void RFCOMM_ProcessFCDCommand(const RFCOMM_Command_t* CommandHeader, const uint8_t* CommandData)
86 {
87 BT_RFCOMM_DEBUG(1, "<< FCD Command");
88 }
89
90 static void RFCOMM_ProcessMSCommand(const RFCOMM_Command_t* CommandHeader, const uint8_t* CommandData)
91 {
92 BT_RFCOMM_DEBUG(1, "<< MS Command");
93 }
94
95 static void RFCOMM_ProcessRPNCommand(const RFCOMM_Command_t* CommandHeader, const uint8_t* CommandData)
96 {
97 BT_RFCOMM_DEBUG(1, "<< RPN Command");
98 }
99
100 static void RFCOMM_ProcessRLSCommand(const RFCOMM_Command_t* CommandHeader, const uint8_t* CommandData)
101 {
102 BT_RFCOMM_DEBUG(1, "<< RLS Command");
103 }
104
105 static void RFCOMM_ProcessDPNCommand(const RFCOMM_Command_t* CommandHeader, const uint8_t* CommandData)
106 {
107 BT_RFCOMM_DEBUG(1, "<< DPN Command");
108
109 /* Skip over the first data byte (Length field) since its size and value are fixed */
110 RFCOMM_Channel_t* RFCOMMChannel = RFCOMM_GetChannelData(CommandData[2]);
111
112 if (RFCOMMChannel == NULL)
113 {
114 // TODO: Channel does not exist - create it
115 }
116
117 RFCOMMChannel->Configured = true;
118
119 // TODO: Read in channel data, ACK request
120 }