00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <malloc.h>
00012 #include <bluezlib.h>
00013
00014 #include <opie2/odebug.h>
00015
00016 #include <OTDriverList.h>
00017 #include <OTGateway.h>
00018 #include <OTDriver.h>
00019
00020 using namespace Opietooth2;
00021
00022 OTDriverList::OTDriverList( OTGateway * _OT ) : QVector<OTDriver>() {
00023
00024 OT = _OT;
00025 setAutoDelete( true );
00026 }
00027
00028 OTDriverList::~OTDriverList() {
00029 }
00030
00031 void OTDriverList::update() {
00032
00033 struct hci_dev_list_req *dl;
00034 struct hci_dev_req *dr;
00035 struct hci_dev_info di;
00036 int cur;
00037
00038 dl = 0;
00039 cur = 0;
00040 do {
00041 cur += 5;
00042
00043 dl = (struct hci_dev_list_req*)
00044 ::realloc( dl, sizeof( struct hci_dev_list_req ) +
00045 ( cur * sizeof(struct hci_dev_req) )
00046 );
00047
00048 if( dl == 0 ) {
00049
00050 exit(1);
00051 }
00052
00053 dl->dev_num = cur;
00054
00055 if( ioctl( OT->getSocket(), HCIGETDEVLIST, (void*)dl) ) {
00056 odebug << "WARNING : cannot read device list. "
00057 << errno
00058 << strerror( errno ) << oendl;
00059 return;
00060 }
00061
00062
00063 } while( dl->dev_num == cur );
00064
00065 if( dl->dev_num != count() ) {
00066
00067 clear();
00068
00069 dr = dl->dev_req;
00070 resize( dl->dev_num );
00071
00072 for( cur=0; cur < dl->dev_num; cur ++) {
00073 memset( &di, 0, sizeof( di ) );
00074 di.dev_id = (dr+cur)->dev_id;
00075
00076
00077 if( ioctl( OT->getSocket(), HCIGETDEVINFO, (void*)&di) != 0 )
00078 continue;
00079 insert( cur, new OTDriver( OT, &di ) );
00080 }
00081
00082 odebug << "Found " << count() << " devices" << oendl;
00083
00084 ::free( dl );
00085 }
00086 }