summaryrefslogtreecommitdiff
authorzecke <zecke>2005-01-09 16:27:40 (UTC)
committer zecke <zecke>2005-01-09 16:27:40 (UTC)
commitebd352b30b5b0278e613e1d1ecc60a5fc7756961 (patch) (side-by-side diff)
tree0a7967a8cf668bf06fd949fbc7e1c9c33043fc60
parentc6432d421a0ec3d158bf40309e98fc0386c4a287 (diff)
downloadopie-ebd352b30b5b0278e613e1d1ecc60a5fc7756961.zip
opie-ebd352b30b5b0278e613e1d1ecc60a5fc7756961.tar.gz
opie-ebd352b30b5b0278e613e1d1ecc60a5fc7756961.tar.bz2
-Do not access the Array out of bounds
-Check that there is a driver before asking to query a non existant
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTGateway.cpp1
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTGateway.h2
2 files changed, 2 insertions, 1 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTGateway.cpp b/noncore/settings/networksettings2/opietooth2/OTGateway.cpp
index e8137dd..1b61a2e 100644
--- a/noncore/settings/networksettings2/opietooth2/OTGateway.cpp
+++ b/noncore/settings/networksettings2/opietooth2/OTGateway.cpp
@@ -52,192 +52,193 @@ OTGateway::OTGateway( void ) : QObject( 0, "OTGateway" ),
AllPeers.setAutoDelete( TRUE );
if ( ( HciCtl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) {
SLOT_ShowError( tr( "error opening hci socket" ) );
return;
}
// load all known devices
updateDrivers();
// load all peers we have ever seen
loadKnownPeers();
// iterate over drivers and find active connections
// adding/updating peers
loadActiveConnections();
// check every 4 seconds the state of BT
timerEvent(0);
RefreshTimer = -1;
setRefreshTimer( 4000 );
// load known link keys
readLinkKeys();
}
// close bluetooth system
OTGateway::~OTGateway( void ) {
if( AllPeersModified ) {
saveKnownPeers();
}
if( Scanning )
delete Scanning;
if( TheOTDevice )
delete TheOTDevice;
if( HciCtl >= 0 ) {
::close( HciCtl );
}
}
void OTGateway::setRefreshTimer( int T ) {
if( RefreshTimer != -1 ) {
killTimer( RefreshTimer );
}
if( T == 0 )
T = 4000;
RefreshTimer = startTimer( T );
}
OTDevice * OTGateway::getOTDevice( ) {
if( TheOTDevice == 0 ) {
// load bluetooth device and check state
TheOTDevice = new OTDevice( this );
connect( TheOTDevice,
SIGNAL( isEnabled( int, bool ) ),
this,
SLOT( SLOT_Enabled( int, bool ) ) );
connect( TheOTDevice,
SIGNAL( error( const QString & ) ),
this,
SLOT( SLOT_ShowError( const QString & ) ) );
}
return TheOTDevice;
}
// start bluetooth (if stopped)
// return TRUE if started
void OTGateway::SLOT_SetEnabled( bool Mode ) {
if( Mode ) {
SLOT_Enable();
return;
}
SLOT_Disable();
}
void OTGateway::SLOT_Enable() {
getOTDevice()->attach();
}
void OTGateway::SLOT_Disable() {
getOTDevice()->detach();
}
bool OTGateway::needsEnabling() {
return getOTDevice()->needsAttach();
}
bool OTGateway::isEnabled() {
if( getOTDevice()->deviceNr() >= 0 &&
+ AllDrivers.count() != 0 &&
driver( getOTDevice()->deviceNr() )->isUp() )
return TRUE;
// else check system
return getOTDevice()->isAttached();
}
void OTGateway::SLOT_ShowError( const QString & S ) {
odebug << S << oendl;
if( ErrorConnectCount > 0 ) {
// pass error
emit error( QString( "<p>" ) + S + "</p>" );
return;
}
QMessageBox::warning( 0,
tr("OTGateway error"),
S );
}
void OTGateway::connectNotify( const char * S ) {
if( S && strcmp( S, "error(const QString&)" ) == 0 ) {
ErrorConnectCount ++;
}
}
void OTGateway::disconnectNotify( const char * S ) {
if( S && strcmp( S, "error(const QString&)" ) == 0 ) {
ErrorConnectCount --;
}
}
void OTGateway::timerEvent( QTimerEvent * ) {
OTDriver * D;
unsigned int oldc = AllDrivers.count();
bool old;
AllDrivers.update();
if( oldc != AllDrivers.count() ) {
updateDrivers();
} else {
for( unsigned int i = 0;
i < AllDrivers.count();
i ++ ) {
D = AllDrivers[i];
old = D->isUp();
if( D->currentState() >= 0 ) {
if( old != D->isUp() ) {
emit stateChange( D, D->isUp() );
}
} else {
// if one driver is unable to provide info
// we refresh all devices
updateDrivers();
return;
}
}
}
}
void OTGateway::SLOT_Enabled( int id, bool Up ) {
odebug << "device " << id << " state " << Up << oendl;
if( Up ) {
// device is up -> detect it
updateDrivers();
if( (unsigned)id >= AllDrivers.count() ) {
// to make sure that the driver really IS detected
AllDrivers[id]->bringUp();
}
} // if DOWN device already down
emit deviceEnabled( Up );
}
void OTGateway::updateDrivers( void ) {
OTDriver * D;
AllDrivers.update();
odebug << "updated drivers. now " << AllDrivers.count() << oendl;
// connect signals for each driver
for( unsigned int i = 0;
i < AllDrivers.count();
i ++ ) {
D = AllDrivers[i];
connect( D,
SIGNAL( error( const QString & ) ),
this,
SLOT( SLOT_ShowError( const QString & ) )
);
diff --git a/noncore/settings/networksettings2/opietooth2/OTGateway.h b/noncore/settings/networksettings2/opietooth2/OTGateway.h
index d97ef35..11c6b30 100644
--- a/noncore/settings/networksettings2/opietooth2/OTGateway.h
+++ b/noncore/settings/networksettings2/opietooth2/OTGateway.h
@@ -1,188 +1,188 @@
#ifndef OTGATEWAY_H
#define OTGATEWAY_H
#include <qobject.h>
#include <qvector.h>
#include <qmap.h>
#include <OTDriverList.h>
#include <OTInquiry.h>
class QPixmap;
namespace Opietooth2 {
class OTDriverList;
class OTDriver;
class OTDevice;
class OTPeer;
class OTInquiry;
class OTPANConnection;
class OTLinkKey;
typedef QVector<OTPeer> PeerVector;
typedef QVector<OTPANConnection> PANConnectionVector;
typedef QArray<OTLinkKey> LinkKeyArray;
class OTLinkKey {
public :
OTLinkKey( const OTDeviceAddress & F,
const OTDeviceAddress & T ) {
From = F;
To = T;
}
const OTDeviceAddress & to()
{ return To; }
const OTDeviceAddress & from()
{ return From; }
OTDeviceAddress From;
OTDeviceAddress To;
};
class OTPANConnection {
public :
OTPANConnection( const QString & Dev, const QString & CT ) {
Device = Dev;
ConnectedTo = CT;
}
QString Device;
QString ConnectedTo;
};
class OTGateway : public QObject {
Q_OBJECT
public :
// single instance
static OTGateway * getOTGateway( void );
static void releaseOTGateway( void );
// convert device type as class to name for that class
static const char * deviceTypeToName( int Cls );
// open bluetooth system
OTGateway( void );
// close bluetooth system
~OTGateway( void );
// get access to system device
OTDevice * getOTDevice();
// return true if this device needs enabling of bluetooth
bool needsEnabling();
// return true if system is running
bool isEnabled();
void setRefreshTimer( int MilleSecs );
// return socket to HCI raw layer
inline int getSocket()
{ return HciCtl; }
OTDriverList & getDriverList()
{ return AllDrivers; }
OTDriver * driver( int nr )
- { return AllDrivers[nr]; }
+ { return AllDrivers.count() == 0 ? 0 : AllDrivers[nr]; }
void updateDrivers();
PANConnectionVector getPANConnections();
// scan neighbourhood using device
void scanNeighbourhood( OTDriver * D = 0 );
void stopScanOfNeighbourhood(void );
void setScanWith( OTDriver * D = 0 )
{ ScanWith = (D) ? D :
(AllDrivers.count() ) ? AllDrivers[0] : 0; }
OTDriver * scanWith( void )
{ return ScanWith; }
// get list of all detected peers
inline const PeerVector & peers( void )
{ return AllPeers; }
// ping peer to see if it is up
bool isPeerUp( const OTDeviceAddress & PAddr,
int timeoutInSec = 1,
int timeoutInUSec = 0,
int retry = 1 );
OTPeer * findPeer( const OTDeviceAddress & Addr );
void removePeer( OTPeer * P );
void addPeer( OTPeer * P );
OTDriver * findDriver( const OTDeviceAddress & Addr );
inline const LinkKeyArray & getLinkKeys() const
{ return AllKeys; }
bool removeLinkKey( unsigned int index );
// return device number if we are connected over any device
// to the channel
// else returns -1
int connectedToRFCommChannel( const OTDeviceAddress & Addr, int channel );
int getFreeRFCommDevice( void );
// return 0 if properly released
int releaseRFCommDevice( int DevNr );
public slots :
// start bluetooth system
void SLOT_SetEnabled( bool );
void SLOT_Enable();
void SLOT_Disable();
// show error
void SLOT_ShowError( const QString & );
void SLOT_Enabled( int, bool );
void SLOT_DriverDisappeared( OTDriver * );
void SLOT_PeerDetected( OTPeer *, bool );
void SLOT_FinishedDetecting();
signals :
// any error
void error( const QString & );
// signal state of bluetooth driver
void stateChange( OTDriver * D, bool State );
// sent when list of drivers changees
void driverListChanged();
// sent when bluetooth on device is enabled
void deviceEnabled( bool );
// sent when a (new if bool = TRUE) peer is detected
void detectedPeer( OTPeer *, bool );
// end of detection process
void finishedDetecting();
protected :
void connectNotify( const char * Signal );
void disconnectNotify( const char * Signal );
void timerEvent( QTimerEvent * );
private :
void loadActiveConnections( void );
void loadKnownPeers( void );
void saveKnownPeers( void );
bool isConnectedTo( int devid,
const OTDeviceAddress & Address );
void readLinkKeys();
static OTGateway * SingleGateway;
static int UseCount;
OTDriver * ScanWith;
OTDriverList AllDrivers;