Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OTDriver.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Mattia Merzi                                    *
00003  *   ottobit@ferrara.linux.it                                              *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #ifndef OTDRIVER_H
00012 #define OTDRIVER_H
00013 
00014 /*
00015  * This class handles the networkSetup with the BlueZ libraries, implements
00016  * most of the bluetooth-related functions and owns the KBTDevice class
00017  * that is a single local bluetooth device representation.
00018  * It is used as a Singleton pattern thru the getDefaultConnector() method.
00019  *
00020  */
00021 #include <qobject.h>
00022 #include <opie2/odebug.h>
00023 #include <bluezlib.h>
00024 
00025 #include <OTDeviceAddress.h>
00026 
00027 namespace Opietooth2 {
00028 
00029 class OTGateway;
00030 class OTHCISocket;
00031 class OTDeviceAddress;
00032 class OTPeer;
00033 
00034 /*
00035  * This is the representation of a
00036  * Bluetooth device for the local
00037  * machine.
00038  */
00039 class OTDriver : public QObject {
00040 
00041       Q_OBJECT
00042 
00043 public:
00044 
00045       OTDriver( OTGateway * Ot, struct hci_dev_info* di);
00046       ~OTDriver();
00047 
00048       inline  OTGateway * gateway() const
00049         { return OT; }
00050 
00051       /*
00052        * Initializes the device using the passed hci_dev_info
00053        * struct, contining the basic information in order to
00054        * talk with the pyisical device.
00055        */
00056       void init(struct hci_dev_info* di);
00057 
00058       /*
00059        * Open the device and obtains a file descriptor to id
00060        * return if open
00061        */
00062       bool open();
00063 
00064       OTHCISocket * openSocket();
00065 
00066       void closeSocket();
00067 
00068       /*
00069        * Return true if the device is opened.
00070        */
00071       int isOpen() 
00072         { return Fd != -1; };
00073 
00074       /*
00075        * Calls the ioctl(HCIDEVRESET) in order to
00076        * reset the device.
00077        */
00078       int reset();
00079 
00080       // set Up if true and not yet up
00081       void setUp( bool Mode );
00082 
00083       /*
00084        * Turn the device up and the reinitializes the device.
00085        * If the device is already up, nothing is done.
00086        */
00087       void bringUp();
00088 
00089       /*
00090        * Turn the device down and the reinitializes the device.
00091        * If the device is already down, nothing is done.
00092        */
00093       void bringDown();
00094 
00095       // is the device UP now
00096       bool isUp() const 
00097          { return IsUp; }
00098 
00099       // get current state 
00100       // return 1 if UP, 0 if DOWN, -1 if ERROR
00101       int currentState();
00102 
00103       /*
00104        * Returns the name of the device. If the device is
00105        * down, the device id is returned.
00106        */
00107       QString name();
00108 
00109       int devId() const 
00110           { return Dev_id; };
00111 
00112       /*
00113        * Returns the string representation of the device id,
00114        * with the same format of the hciconfig tool.
00115        */
00116       QString devname() 
00117           { return Dev; };
00118 
00119       /*
00120        * Returns the file descriptor for the local
00121        * networkSetup to this device
00122        */
00123       int fd() const 
00124           { return Fd; };
00125       void setfd(int _fd) 
00126           { Fd = _fd; };
00127 
00128       void setType(int _type) 
00129          { Type = _type; };
00130       int type() const 
00131          { return Type; };
00132       QString strType();
00133 
00134       int iscan() const 
00135         { return Iscan; }
00136       void setIScan(int _iscan) 
00137         { Iscan = _iscan; }
00138 
00139       int pscan() const 
00140         { return Pscan; }
00141       void setPScan(int _pscan) 
00142         { Pscan = _pscan; }
00143 
00144       int authentication() const 
00145         { return Auth; }
00146       void setAuthentication(int _auth) 
00147         { Auth = _auth; }
00148 
00149       int encryption() const 
00150         { return Encrypt; }
00151       void setEncryption(int _encrypt) 
00152         { Encrypt = _encrypt; }
00153 
00154       void setDevId(int _dev_id) 
00155         { Dev_id = _dev_id; };
00156       void setDev(char* _dev) 
00157         { Dev = _dev; };
00158 
00159       void setFlags( unsigned long flags);
00160 
00161       const OTDeviceAddress & address() 
00162         { return Address; }
00163 
00164       void setFeatures( unsigned char * _f);
00165       QString features() 
00166         { return Features; }
00167 
00168       void setManufacturer(int compid);
00169       QString manufacturer() 
00170         { return Manufacturer; }
00171 
00172       QString revision();
00173 
00174       void setScanMode(bool iscan, bool pscan);
00175       void setClass(unsigned long cls);
00176 
00177       void changeDevName(const char* name);
00178       void changeEncryption(bool _encryption);
00179       void changeAuthentication(bool _auth);
00180 
00181       void getClass( QString & service,  
00182                      QString & device );
00183       void changeClass( unsigned char service, 
00184                         unsigned char major, 
00185                         unsigned char minor);
00186 
00187       QString getPeerName( const OTDeviceAddress & PAddr );
00188 
00189       // address must be connected to this driver
00190       long getLinkQuality( const OTDeviceAddress & Address );
00191 
00192 signals :
00193 
00194       void error( const QString & );
00195       void stateChange( OTDriver * , bool );
00196       void driverDisappeared( OTDriver * );
00197 
00198 private slots :
00199 
00200       /*
00201        * Reinitializes the device, obtaining a fresh
00202        * hci_dev_info structure.
00203        */
00204       void reinit();
00205       void SLOT_CloseFd();
00206 
00207 private:
00208 
00209       QString getRevEricsson();
00210       QString getRevCsr(unsigned short rev);
00211 
00212       QString     Name;
00213       QString     Dev;
00214       QString     Revision;
00215       QString     Manufacturer;
00216       OTDeviceAddress  Address;
00217       QString     Features;
00218       QTimer  *   AutoClose;
00219 
00220       int         Dev_id,Fd,Type;
00221       bool        IsUp;
00222       int         Iscan,Pscan,Auth,Encrypt;
00223 
00224       // socket bound to this device
00225       OTHCISocket * Socket;
00226 
00227       // backpointer to opietooth system 
00228       OTGateway *   OT;
00229 };
00230 
00231 }
00232 #endif

Generated on Sat Nov 5 16:17:55 2005 for OPIE by  doxygen 1.4.2