2
/***************************************************************************
3
* Copyright (C) 2003 by Fred Schaettgen *
4
* kdebluetooth@schaettgen.de *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
10
***************************************************************************/
25
#include <sys/ioctl.h>
26
#include <sys/socket.h>
27
#include <asm/types.h>
28
#include <netinet/in.h>
30
#include "adapter_old.h"
32
#include <sys/socket.h>
33
#include <bluetooth/bluetooth.h>
34
#include <bluetooth/hci.h>
35
#include <bluetooth/hci_lib.h>
36
#include <hcisocket.h>
41
DeviceAddress RAdapter::getAddress() const
46
QString RAdapter::getName() const
51
int RAdapter::getIndex() const
56
RAdapter::RAdapter(int index, const DeviceAddress& address, QString name)
59
this->address = address;
64
RAdapter::ConnectionInfoVector RAdapter::getAclConnections() const
66
ConnectionInfoVector ret;
68
hci_conn_list_req *cl;
70
char buf[10*sizeof(*ci) + sizeof(*cl)];
71
cl = (hci_conn_list_req*)buf;
72
cl->dev_id = getIndex();
76
HciSocket s(NULL, "", getIndex());
81
if (ioctl(s.socket(), HCIGETCONNLIST, (void*)cl)) {
82
kdWarning() << "Can't get connection list: "
83
<< QString::fromLocal8Bit(strerror(errno)) << endl;
87
for (int i=0; i < cl->conn_num; i++, ci++) {
88
if (ci->type == ACL_LINK) {
90
i.address = DeviceAddress(ci->bdaddr, false);
91
i.handle = ci->handle;
92
i.out = (ci->out != 0);
93
i.type = ConnectionType(ci->type);
95
case 0: i.state = NOT_CONNECTED; break;
96
case 1: i.state = CONNECTED; break;
97
case 5: i.state = CONNECTING; break;
98
default: i.state = UNKNOWN_STATE;
100
i.link_mode = ci->link_mode;
108
RAdapter::ConnectionState RAdapter::getAclConnectionState(const DeviceAddress& addr) const
110
ConnectionState ret = UNKNOWN_STATE;
112
hci_conn_list_req *cl;
114
char buf[10*sizeof(*ci) + sizeof(*cl)];
115
cl = (hci_conn_list_req*)buf;
116
cl->dev_id = getIndex();
120
HciSocket s(NULL, "", getIndex());
125
if (ioctl(s.socket(), HCIGETCONNLIST, (void*)cl)) {
126
kdWarning() << "Can't get connection list"
127
<< QString::fromLocal8Bit(strerror(errno)) << endl;
132
for (int i=0; i < cl->conn_num; i++, ci++) {
133
if ((ci->type == ACL_LINK) &&
134
(DeviceAddress(ci->bdaddr,false) == addr)) {
140
case 0: ret = NOT_CONNECTED; break;
141
case 1: ret = CONNECTED; break;
142
case 5: ret = CONNECTING; break;
143
default: ret = UNKNOWN_STATE;
150
int RAdapter::getClassOfDevice() const
152
HciSocket s(NULL, "", getIndex());
157
if (hci_read_class_of_dev(s.socket(), cls, 1000) < 0) {
162
return cls[2]*256*256+cls[1]*256+cls[0];
170
int Adapters::count()
172
return adapters.size();
175
const RAdapter& Adapters::operator[](int n) const
180
void Adapters::update()
183
hci_for_each_dev(HCI_UP, dev_info, (long int)this);
186
int Adapters::dev_info(int s, int dev_id, long arg)
188
reinterpret_cast<Adapters*>(arg)->dev_info(s, dev_id);
192
void Adapters::dev_info(int s, int dev_id)
194
struct hci_dev_info di;
196
if (ioctl(s, HCIGETDEVINFO, (void*) &di))
199
RAdapter a = RAdapter(dev_id, DeviceAddress(di.bdaddr), QString(di.name));
200
adapters.push_back(a);