LMS 2012
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
c_bt.h
Go to the documentation of this file.
1 /*
2  * LEGO® MINDSTORMS EV3
3  *
4  * Copyright (C) 2010-2013 The LEGO Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef C_BT_H_
22 #define C_BT_H_
23 
24 
25 #include "lms2012.h"
26 #include <bluetooth/bluetooth.h>
27 #include <bluetooth/rfcomm.h>
28 #include <sys/poll.h>
29 #include <sys/ioctl.h>
30 #include <bluetooth/hci.h>
31 
32 
33 #define NONVOL_BT_DATA "settings/nonvolbt"
34 
35 
36 #define MAX_DEV_TABLE_ENTRIES 30
37 #define BT_CH_OFFSET 2
38 #define MAX_NAME_SIZE 32
39 #define MAX_BT_NAME_SIZE 248
40 
41 #define MAX_BUNDLE_ID_SIZE 24
42 #define MAX_BUNDLE_SEED_ID_SIZE 11
43 
44 
45 enum
46 {
56 };
57 
58 
59 // Defines related to Device List
60 enum
61 {
62  DEV_EMPTY = 0x00,
63  DEV_KNOWN = 0x01,
64 };
65 
66 enum
67 {
70 };
71 
72 enum
73 {
77 };
78 
79 // Defines related to Channels
80 enum
81 {
85 };
86 
87 // Defines related to BtInstance.HciSocket.Busy
88 enum
89 {
90  HCI_IDLE = 0x00,
91  HCI_ONOFF = 0x01,
92  HCI_VISIBLE = 0x02,
93  HCI_NAME = 0x04,
94  HCI_SCAN = 0x08,
95  HCI_CONNECT = 0x10,
97  HCI_RESTART = 0x40,
98  HCI_FAIL = 0x80
99 };
100 
101 
102 // Buffer to read into from the socket
103 typedef struct
104 {
105  UBYTE Buf[1024];
109 }READBUF;
110 
111 
112 // Buffer to write into from the socket
113 typedef struct
114 {
115  UBYTE Buf[1024];
118 }WRITEBUF;
119 
120 
121 // Buffer to fill complete message into from READBUF
122 // only one Messages can fit into this buffer
123 typedef struct
124 {
125  UBYTE Buf[1024];
131 }MSGBUF;
132 
133 
134 // Control socket
135 typedef struct
136 {
138  struct pollfd p;
141 }HCISOCKET;
142 
143 
144 // Socket to listen for incoming requests
145 typedef struct
146 {
148  struct sockaddr_rc loc_addr;
149  struct sockaddr_rc rem_addr;
151 }LISTENSOCKET;
152 
153 
154 // Communication sockets
155 typedef struct
156 {
158  bdaddr_t Addr;
159  struct timeval Cmdtv;
160  fd_set Cmdfds;
161 }BTSOCKET;
162 
163 
164 typedef struct
165 {
166  char Name[MAX_BT_NAME_SIZE];
167  bdaddr_t Adr;
169  UBYTE DevClass[3];
170  UBYTE Passkey[6];
174 }DEVICELIST;
175 
176 
177 typedef struct
178 {
179  char Name[MAX_BT_NAME_SIZE];
180  bdaddr_t Adr;
181  UBYTE DevClass[3];
185 }SEARCHLIST;
186 
187 
188 typedef struct
189 {
195 }BTCH;
196 
197 
198 typedef struct
199 {
207 }NONVOLBT;
208 
209 typedef struct
210 {
213  char Name[MAX_BT_NAME_SIZE];
214  bdaddr_t Adr;
215  UBYTE DevClass[3];
216 }INCOMMING;
217 
218 typedef struct
219 {
221 }OUTGOING;
222 
223 typedef struct
224 {
225  bdaddr_t Adr;
227  UBYTE Pin[10];
229 }TRUSTED_DEV;
230 
231 
232 typedef struct
233 {
234  //*****************************************************************************
235  // Bluetooth Global variables
236  //*****************************************************************************
237 
238  HCISOCKET HciSocket; // Control socket
239  LISTENSOCKET ListenSocket; // Socket to listen for incoming requests
240  BTCH BtCh[NO_OF_BT_CHS]; // Communication sockets
243 
248  char Adr[13];
255 
265  char BtName[vmBRICKNAMESIZE];
266 }BT_GLOBALS;
267 
268 
269 void IncommingConnect(void);
270 void BtInit(char *pName);
271 void BtExit(void);
272 void BtUpdate(void);
273 void BtTxMsgs(void);
274 UBYTE cBtConnect(UBYTE *pName);
275 UBYTE cBtDisconnect(UBYTE *pName);
276 UBYTE cBtDiscChNo(UBYTE ChNo);
277 
278 UWORD cBtReadCh0(UBYTE *pBuf, UWORD Length);
279 UWORD cBtReadCh1(UBYTE *pBuf, UWORD Length);
280 UWORD cBtReadCh2(UBYTE *pBuf, UWORD Length);
281 UWORD cBtReadCh3(UBYTE *pBuf, UWORD Length);
282 UWORD cBtReadCh4(UBYTE *pBuf, UWORD Length);
283 UWORD cBtReadCh5(UBYTE *pBuf, UWORD Length);
284 UWORD cBtReadCh6(UBYTE *pBuf, UWORD Length);
285 UWORD cBtReadCh7(UBYTE *pBuf, UWORD Length);
286 
287 UWORD cBtDevWriteBuf(UBYTE *pBuf, UWORD Size);
288 UWORD cBtDevWriteBuf1(UBYTE *pBuf, UWORD Size);
289 UWORD cBtDevWriteBuf2(UBYTE *pBuf, UWORD Size);
290 UWORD cBtDevWriteBuf3(UBYTE *pBuf, UWORD Size);
291 UWORD cBtDevWriteBuf4(UBYTE *pBuf, UWORD Size);
292 UWORD cBtDevWriteBuf5(UBYTE *pBuf, UWORD Size);
293 UWORD cBtDevWriteBuf6(UBYTE *pBuf, UWORD Size);
294 UWORD cBtDevWriteBuf7(UBYTE *pBuf, UWORD Size);
295 
296 UBYTE cBtI2cBufReady(void);
297 UWORD cBtI2cToBtBuf(UBYTE *pBuf, UWORD Size);
298 
299 // Generic Bluetooth commands
301 UBYTE BtGetVisibility(void);
303 UBYTE BtGetOnOff(UBYTE *On);
304 UBYTE BtSetMode2(UBYTE Mode2);
305 UBYTE BtGetMode2(UBYTE *pMode2);
306 UBYTE BtStartScan(void);
307 UBYTE BtStopScan(void);
309 UBYTE cBtGetConnListEntry(UBYTE Item, UBYTE *pName, SBYTE Length, UBYTE* pType);
311 UBYTE cBtGetDevListEntry(UBYTE Item, SBYTE *pConnected, SBYTE *pType, UBYTE *pName, SBYTE Length);
314 UBYTE cBtGetSearchListEntry(UBYTE Item, SBYTE *pConnected, SBYTE *pType, SBYTE *pParred, UBYTE *pName, SBYTE Length);
316 void DecodeMode1(UBYTE BufNo);
317 
318 UBYTE cBtGetStatus(void);
319 void cBtGetId(UBYTE *pId, UBYTE Length);
320 UBYTE cBtSetName(UBYTE *pName, UBYTE Length);
321 UBYTE cBtGetChNo(UBYTE *pName, UBYTE *pChNo);
322 void cBtGetIncoming(UBYTE *pName, UBYTE *pCod, UBYTE Len);
323 UBYTE cBtGetEvent(void);
324 UBYTE cBtSetPin(UBYTE *pPin);
325 UBYTE cBtSetPasskey(UBYTE Accept);
326 
327 void cBtSetTrustedDev(UBYTE *pBtAddr, UBYTE *pPin, UBYTE PinSize);
328 
330 UWORD cBtSetBundleSeedId(UBYTE *pSeedId);
331 
332 
333 #endif /* C_BT_H_ */
UWORD cBtReadCh3(UBYTE *pBuf, UWORD Length)
Definition: c_bt.c:771
UBYTE cBtGetConnListEntry(UBYTE Item, UBYTE *pName, SBYTE Length, UBYTE *pType)
Definition: c_bt.c:3489
TRUSTED_DEV TrustedDev
Definition: c_bt.h:247
READBUF ReadBuf
Definition: c_bt.h:191
Definition: c_bt.h:74
Definition: c_bt.h:123
UWORD Status
Definition: c_bt.h:129
UWORD cBtSetBundleId(UBYTE *pId)
Definition: c_bt.c:4265
UWORD InPtr
Definition: c_bt.h:106
UBYTE BtGetOnOff(UBYTE *On)
Definition: c_bt.c:2042
UBYTE cBtSetPin(UBYTE *pPin)
Definition: c_bt.c:4191
UWORD ConnHandle
Definition: c_bt.h:212
UWORD cBtReadCh5(UBYTE *pBuf, UWORD Length)
Definition: c_bt.c:815
UBYTE ChNo
Definition: c_bt.h:220
UBYTE cBtI2cBufReady(void)
Definition: c_bt.c:2523
UWORD cBtDevWriteBuf7(UBYTE *pBuf, UWORD Size)
Definition: c_bt.c:2667
NONVOLBT NonVol
Definition: c_bt.h:259
UBYTE cBtGetHciBusyFlag(void)
Definition: c_bt.c:3433
BTSOCKET BtSocket
Definition: c_bt.h:193
signed char SBYTE
Basic Type used to symbolise 8 bit signed values.
Definition: lmstypes.h:33
UBYTE PinLen
Definition: c_bt.h:226
Definition: c_bt.h:155
SLONG Socket
Definition: c_bt.h:147
void cBtGetIncoming(UBYTE *pName, UBYTE *pCod, UBYTE Len)
Definition: c_bt.c:4184
UWORD OutPtr
Definition: c_bt.h:107
bdaddr_t Adr
Definition: c_bt.h:225
UWORD ConnHandle
Definition: c_bt.h:168
UBYTE BtStartScan(void)
Definition: c_bt.c:646
Definition: c_bt.h:98
UBYTE Connected
Definition: c_bt.h:182
#define MAX_DEV_TABLE_ENTRIES
Definition: c_bt.h:36
void DecodeMode1(UBYTE BufNo)
Definition: c_bt.c:920
SLONG OldState
Definition: c_bt.h:257
UWORD RemMsgLen
Definition: c_bt.h:128
UWORD cBtDevWriteBuf6(UBYTE *pBuf, UWORD Size)
Definition: c_bt.c:2652
#define MAX_BT_NAME_SIZE
Definition: c_bt.h:39
UWORD cBtReadCh1(UBYTE *pBuf, UWORD Length)
Definition: c_bt.c:727
UWORD cBtSetBundleSeedId(UBYTE *pSeedId)
Definition: c_bt.c:4279
Definition: c_bt.h:93
UBYTE cBtGetEvent(void)
Definition: c_bt.c:4174
INCOMMING Incoming
Definition: c_bt.h:245
SLONG State
Definition: c_bt.h:256
LISTENSOCKET ListenSocket
Definition: c_bt.h:239
UWORD cBtReadCh0(UBYTE *pBuf, UWORD Length)
Definition: c_bt.c:706
Definition: c_bt.h:198
UBYTE cBtSetPasskey(UBYTE Accept)
Definition: c_bt.c:4212
UBYTE Busy
Definition: c_bt.h:140
UWORD cBtReadCh6(UBYTE *pBuf, UWORD Length)
Definition: c_bt.c:837
UBYTE Visible
Definition: c_bt.h:202
UWORD MsgLen
Definition: c_bt.h:127
void BtTxMsgs(void)
Definition: c_bt.c:2461
UWORD cBtDevWriteBuf(UBYTE *pBuf, UWORD Size)
Definition: c_bt.c:2547
UWORD cBtDevWriteBuf2(UBYTE *pBuf, UWORD Size)
Definition: c_bt.c:2592
UBYTE WaitForEvent
Definition: c_bt.h:139
UBYTE BtSetOnOff(UBYTE On)
Definition: c_bt.c:2000
UBYTE cBtGetNoOfConnListEntries(void)
Definition: c_bt.c:3483
UBYTE DecodeMode
Definition: c_bt.h:204
bdaddr_t Adr
Definition: c_bt.h:214
UBYTE PageState
Definition: c_bt.h:252
MSGBUF MsgBuf
Definition: c_bt.h:192
unsigned int ULONG
Basic Type used to symbolise 32 bit unsigned values.
Definition: lmstypes.h:31
bdaddr_t Adr
Definition: c_bt.h:180
UBYTE Status
Definition: c_bt.h:194
Definition: c_bt.h:63
ULONG opt
Definition: c_bt.h:150
UBYTE NoOfFoundDev
Definition: c_bt.h:250
UBYTE SspPairingMethod
Definition: c_bt.h:264
UBYTE NoOfFoundNames
Definition: c_bt.h:251
Definition: c_bt.h:62
Definition: c_bt.h:113
Definition: c_bt.h:83
ULONG Passkey
Definition: c_bt.h:211
UWORD cBtDevWriteBuf3(UBYTE *pBuf, UWORD Size)
Definition: c_bt.c:2607
Definition: c_bt.h:90
UWORD cBtReadCh4(UBYTE *pBuf, UWORD Length)
Definition: c_bt.c:793
UBYTE cBtGetChNo(UBYTE *pName, UBYTE *pChNo)
Definition: c_bt.c:3680
HCISOCKET HciSocket
Definition: c_bt.h:238
#define MAX_BUNDLE_ID_SIZE
Definition: c_bt.h:41
OUTGOING OutGoing
Definition: c_bt.h:246
UBYTE cBtGetDevListEntry(UBYTE Item, SBYTE *pConnected, SBYTE *pType, UBYTE *pName, SBYTE Length)
Definition: c_bt.c:3523
Definition: c_bt.h:94
UBYTE cBtConnect(UBYTE *pName)
Definition: c_bt.c:2276
WRITEBUF WriteBuf
Definition: c_bt.h:190
void cBtGetId(UBYTE *pId, UBYTE Length)
Definition: c_bt.c:3645
Definition: c_bt.h:218
UBYTE cBtGetStatus(void)
Definition: c_bt.c:3621
UBYTE ScanState
Definition: c_bt.h:253
void BtUpdate(void)
Definition: c_bt.c:1572
bdaddr_t Adr
Definition: c_bt.h:167
UWORD cBtDevWriteBuf4(UBYTE *pBuf, UWORD Size)
Definition: c_bt.c:2622
ULONG Delay
Definition: c_bt.h:258
UBYTE DevListEntries
Definition: c_bt.h:201
UBYTE cBtSetName(UBYTE *pName, UBYTE Length)
Definition: c_bt.c:3651
UBYTE Parred
Definition: c_bt.h:183
unsigned char UBYTE
Basic Type used to symbolise 8 bit unsigned values.
Definition: lmstypes.h:29
UWORD cBtDevWriteBuf1(UBYTE *pBuf, UWORD Size)
Definition: c_bt.c:2577
UBYTE cBtGetNoOfSearchListEntries(void)
Definition: c_bt.c:3536
UBYTE Status
Definition: c_bt.h:173
UWORD InPtr
Definition: c_bt.h:126
unsigned short UWORD
Basic Type used to symbolise 16 bit unsigned values.
Definition: lmstypes.h:30
UBYTE DecodeMode
Definition: c_bt.h:263
void cBtSetTrustedDev(UBYTE *pBtAddr, UBYTE *pPin, UBYTE PinSize)
Definition: c_bt.c:4240
UBYTE RestartSeqCnt
Definition: c_bt.h:261
UBYTE ChNo
Definition: c_bt.h:184
UWORD cBtI2cToBtBuf(UBYTE *pBuf, UWORD Size)
Definition: c_bt.c:2536
UBYTE cBtDiscChNo(UBYTE ChNo)
Definition: c_bt.c:2396
Definition: c_bt.h:103
READBUF Mode2Buf
Definition: c_bt.h:241
UBYTE BtGetVisibility(void)
Definition: c_bt.c:2114
UBYTE BtGetMode2(UBYTE *pMode2)
Definition: c_bt.c:1990
UBYTE BtSetVisibility(UBYTE State)
Definition: c_bt.c:2076
WRITEBUF Mode2WriteBuf
Definition: c_bt.h:242
SLONG Socket
Definition: c_bt.h:137
UBYTE BtSetMode2(UBYTE Mode2)
Definition: c_bt.c:1936
UBYTE Connected
Definition: c_bt.h:171
void BtExit(void)
Definition: c_bt.c:426
void IncommingConnect(void)
UWORD Status
Definition: c_bt.h:108
UWORD InPtr
Definition: c_bt.h:116
UBYTE BtStopScan(void)
Definition: c_bt.c:664
UBYTE cBtGetSearchListEntry(UBYTE Item, SBYTE *pConnected, SBYTE *pType, SBYTE *pParred, UBYTE *pName, SBYTE Length)
Definition: c_bt.c:3542
Definition: c_bt.h:188
UWORD cBtDevWriteBuf5(UBYTE *pBuf, UWORD Size)
Definition: c_bt.c:2637
UWORD OutPtr
Definition: c_bt.h:117
UBYTE cBtDisconnect(UBYTE *pName)
Definition: c_bt.c:2415
UBYTE Events
Definition: c_bt.h:262
SLONG Socket
Definition: c_bt.h:157
UWORD cBtReadCh2(UBYTE *pBuf, UWORD Length)
Definition: c_bt.c:749
UBYTE ChNo
Definition: c_bt.h:172
void BtInit(char *pName)
Definition: c_bt.c:349
UBYTE cBtDeleteFavourItem(UBYTE *pName)
Definition: c_bt.c:3556
UBYTE On
Definition: c_bt.h:203
UBYTE Status
Definition: c_bt.h:228
UWORD cBtReadCh7(UBYTE *pBuf, UWORD Length)
Definition: c_bt.c:858
UBYTE cBtGetNoOfDevListEntries(void)
Definition: c_bt.c:3517
bdaddr_t Addr
Definition: c_bt.h:158
UBYTE LargeMsg
Definition: c_bt.h:130
signed int SLONG
Basic Type used to symbolise 32 bit signed values.
Definition: lmstypes.h:35
UBYTE SearchIndex
Definition: c_bt.h:249
#define MAX_BUNDLE_SEED_ID_SIZE
Definition: c_bt.h:42
UBYTE NoOfConnDevs
Definition: c_bt.h:254
fd_set Cmdfds
Definition: c_bt.h:160
Definition: c_bt.h:91
UBYTE OnOffSeqCnt
Definition: c_bt.h:260