summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/opietooth2/OTDriver.h
blob: 899fab4f7e489054df6578530f8838ea87c0f31a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/***************************************************************************
 *   Copyright (C) 2003 by Mattia Merzi                                    *
 *   ottobit@ferrara.linux.it                                              *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef OTDRIVER_H
#define OTDRIVER_H

/*
 * This class handles the networkSetup with the BlueZ libraries, implements
 * most of the bluetooth-related functions and owns the KBTDevice class
 * that is a single local bluetooth device representation.
 * It is used as a Singleton pattern thru the getDefaultConnector() method.
 *
 */
#include <qobject.h>
#include <opie2/odebug.h>
#include <bluezlib.h>

#include <OTDeviceAddress.h>

namespace Opietooth2 {

class OTGateway;
class OTHCISocket;
class OTDeviceAddress;
class OTPeer;

/*
 * This is the representation of a
 * Bluetooth device for the local
 * machine.
 */
class OTDriver : public QObject {

      Q_OBJECT

public:

      OTDriver( OTGateway * Ot, struct hci_dev_info* di);
      ~OTDriver();

      inline  OTGateway * gateway() const
        { return OT; }

      /*
       * Initializes the device using the passed hci_dev_info
       * struct, contining the basic information in order to
       * talk with the pyisical device.
       */
      void init(struct hci_dev_info* di);

      /*
       * Open the device and obtains a file descriptor to id
       * return if open
       */
      bool open();

      OTHCISocket * openSocket();

      void closeSocket();

      /*
       * Return true if the device is opened.
       */
      int isOpen() 
        { return Fd != -1; };

      /*
       * Calls the ioctl(HCIDEVRESET) in order to
       * reset the device.
       */
      int reset();

      // set Up if true and not yet up
      void setUp( bool Mode );

      /*
       * Turn the device up and the reinitializes the device.
       * If the device is already up, nothing is done.
       */
      void bringUp();

      /*
       * Turn the device down and the reinitializes the device.
       * If the device is already down, nothing is done.
       */
      void bringDown();

      // is the device UP now
      bool isUp() const 
         { return IsUp; }

      // get current state 
      // return 1 if UP, 0 if DOWN, -1 if ERROR
      int currentState();

      /*
       * Returns the name of the device. If the device is
       * down, the device id is returned.
       */
      QString name();

      int devId() const 
          { return Dev_id; };

      /*
       * Returns the string representation of the device id,
       * with the same format of the hciconfig tool.
       */
      QString devname() 
          { return Dev; };

      /*
       * Returns the file descriptor for the local
       * networkSetup to this device
       */
      int fd() const 
          { return Fd; };
      void setfd(int _fd) 
          { Fd = _fd; };

      void setType(int _type) 
         { Type = _type; };
      int type() const 
         { return Type; };
      QString strType();

      int iscan() const 
        { return Iscan; }
      void setIScan(int _iscan) 
        { Iscan = _iscan; }

      int pscan() const 
        { return Pscan; }
      void setPScan(int _pscan) 
        { Pscan = _pscan; }

      int authentication() const 
        { return Auth; }
      void setAuthentication(int _auth) 
        { Auth = _auth; }

      int encryption() const 
        { return Encrypt; }
      void setEncryption(int _encrypt) 
        { Encrypt = _encrypt; }

      void setDevId(int _dev_id) 
        { Dev_id = _dev_id; };
      void setDev(char* _dev) 
        { Dev = _dev; };

      void setFlags( unsigned long flags);

      const OTDeviceAddress & address() 
        { return Address; }

      void setFeatures( unsigned char * _f);
      QString features() 
        { return Features; }

      void setManufacturer(int compid);
      QString manufacturer() 
        { return Manufacturer; }

      QString revision();

      void setScanMode(bool iscan, bool pscan);
      void setClass(unsigned long cls);

      void changeDevName(const char* name);
      void changeEncryption(bool _encryption);
      void changeAuthentication(bool _auth);

      void getClass( QString & service,  
                     QString & device );
      void changeClass( unsigned char service, 
                        unsigned char major, 
                        unsigned char minor);

      QString getPeerName( const OTDeviceAddress & PAddr );

      // address must be connected to this driver
      long getLinkQuality( const OTDeviceAddress & Address );

signals :

      void error( const QString & );
      void stateChange( OTDriver * , bool );
      void driverDisappeared( OTDriver * );

private slots :

      /*
       * Reinitializes the device, obtaining a fresh
       * hci_dev_info structure.
       */
      void reinit();
      void SLOT_CloseFd();

private:

      QString getRevEricsson();
      QString getRevCsr(unsigned short rev);

      QString     Name;
      QString     Dev;
      QString     Revision;
      QString     Manufacturer;
      OTDeviceAddress  Address;
      QString     Features;
      QTimer  *   AutoClose;

      int         Dev_id,Fd,Type;
      bool        IsUp;
      int         Iscan,Pscan,Auth,Encrypt;

      // socket bound to this device
      OTHCISocket * Socket;

      // backpointer to opietooth system 
      OTGateway *   OT;
};

}
#endif