00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <config.h>
00018 #ifdef OASYS_BLUETOOTH_ENABLED
00019
00020 #include <stdlib.h>
00021 #include <sys/types.h>
00022 #include <sys/fcntl.h>
00023 #include <sys/socket.h>
00024
00025 #include "Bluetooth.h"
00026 #include "BluetoothInquiry.h"
00027
00028 namespace oasys {
00029
00030 BluetoothInquiry::BluetoothInquiry(const char * logbase)
00031 : Logger("BluetoothInquiry", logbase),
00032 num_responses_i_(-1),
00033 pos_(0),
00034 flags_(0L)
00035 {
00036 memset(&info_[0],0,sizeof(inquiry_info)*BT_INQ_NUM_RESP);
00037 }
00038
00039 BluetoothInquiry::~BluetoothInquiry()
00040 {
00041 }
00042
00043 int
00044 BluetoothInquiry::inquire()
00045 {
00046
00047
00048
00049
00050
00051
00052 inquiry_info *ii = &info_[0];
00053 num_responses_i_ = Bluetooth::hci_inquiry(-1,BT_INQ_LENGTH,BT_INQ_NUM_RESP,
00054 0,&ii,flags_);
00055 return num_responses_i_;
00056 }
00057
00058 void
00059 BluetoothInquiry::reset()
00060 {
00061 pos_ = 0;
00062 num_responses_i_ = -1;
00063 memset(&info_[0],0,sizeof(inquiry_info)*BT_INQ_NUM_RESP);
00064 flags_ |= IREQ_CACHE_FLUSH;
00065 }
00066
00067 int
00068 BluetoothInquiry::first(bdaddr_t& addr)
00069 {
00070 reset();
00071 return next(addr);
00072 }
00073
00074 int
00075 BluetoothInquiry::next(bdaddr_t& addr)
00076 {
00077 if((pos_ >= num_responses_i_) ||
00078 (bacmp(&(info_[pos_].bdaddr),BDADDR_ANY) == 0))
00079 {
00080 reset();
00081 return -1;
00082 }
00083 log_debug("BluetoothInquiry::next(%d)",pos_);
00084 bacpy(&addr,&(info_[pos_].bdaddr));
00085 pos_++;
00086 return 0;
00087 }
00088
00089 }
00090 #endif