00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "bluez-bluetoothsecurityadaptor.h"
00022 #include <kdebug.h>
00023 #include <ctime>
00024
00025 BluezBluetoothSecurityPasskeyAgentAdaptor::BluezBluetoothSecurityPasskeyAgentAdaptor(BluezBluetoothSecurity * security)
00026 :QDBusAbstractAdaptor(security),security(security),conn(QDBusConnection::systemBus())
00027 {
00028 serviceName = QString("/org/kde/solid/BluezBluetoothSecurityPasskeyAgentAdaptor%1").arg(time(NULL));
00029 bool done = conn.registerObject(serviceName,security,QDBusConnection::ExportAdaptors);
00030 if (!done) {
00031 kDebug() << "Failed to register the object: " << conn.lastError().name() << " : " << conn.lastError().message();
00032 serviceName = "";
00033 } else {
00034 kDebug() << "DBus service registered at "<< serviceName <<endl;
00035
00036 QDBusInterface iface("org.bluez", "/org/bluez","org.bluez.Security",conn, this);
00037 iface.call("RegisterDefaultPasskeyAgent",serviceName);
00038 if (iface.lastError().isValid()) {
00039 kDebug() << "RegisterDefaultPasskeyAgent failed :" << iface.lastError().name() << " : " << iface.lastError().message();
00040 serviceName = "";
00041 } else {
00042 kDebug() << "RegisterDefaultPasskeyAgent succesfull!";
00043 }
00044 }
00045
00046 }
00047
00048 BluezBluetoothSecurityPasskeyAgentAdaptor::~ BluezBluetoothSecurityPasskeyAgentAdaptor()
00049 {
00050 kDebug() << k_funcinfo;
00051 if (!serviceName.isEmpty())
00052 {
00053 QDBusInterface iface("org.bluez", "/org/bluez","org.bluez.Security",conn, this);
00054 iface.call("UnregisterDefaultPasskeyAgent",serviceName);
00055 if (iface.lastError().isValid()) {
00056 kDebug() << "UnregisterDefaultPasskeyAgent failed :" << iface.lastError().name() << " : " << iface.lastError().message();
00057 serviceName = "";
00058 } else {
00059 kDebug() << "UnregisterDefaultPasskeyAgent Successful!:" << iface.lastError().name() << " : " << iface.lastError().message();
00060 }
00061 }
00062 }
00063
00064 QString BluezBluetoothSecurityPasskeyAgentAdaptor::Request(const QString & path, const QString & address, bool numeric,const QDBusMessage &msg)
00065 {
00066 kDebug() << k_funcinfo;
00067 Q_UNUSED(path)
00068 if (security) {
00069 QString answer = security->request(address,numeric);
00070 if (!answer.isEmpty()) {
00071 return answer;
00072 } else {
00073 QDBusMessage error = msg.createErrorReply("org.bluez.Error.Rejected","Pairing request rejected");
00074 QDBusConnection::systemBus().send(error);
00075 }
00076 }
00077 return "";
00078 }
00079
00080 void BluezBluetoothSecurityPasskeyAgentAdaptor::Confirm(const QString & path, const QString & address, const QString & value,const QDBusMessage &msg)
00081 {
00082 kDebug() << k_funcinfo;
00083 Q_UNUSED(path)
00084 if (security) {
00085 if(security->confirm(address,value)) {
00086 kDebug() << "Confirmed pin for " << address;
00087 } else {
00088 QDBusMessage error = msg.createErrorReply("org.bluez.Error.Rejected","Pairing request rejected");
00089 QDBusConnection::systemBus().send(error);
00090 }
00091 }
00092 }
00093
00094 void BluezBluetoothSecurityPasskeyAgentAdaptor::Display(const QString & path, const QString & address, const QString & value)
00095 {
00096 kDebug() << k_funcinfo;
00097 Q_UNUSED(path)
00098 if (security) {
00099 security->display(address,value);
00100 }
00101 }
00102
00103 void BluezBluetoothSecurityPasskeyAgentAdaptor::Keypress(const QString & path, const QString & address)
00104 {
00105 kDebug() << k_funcinfo;
00106 Q_UNUSED(path)
00107 if (security) {
00108 security->keypress(address);
00109 }
00110 }
00111
00112 void BluezBluetoothSecurityPasskeyAgentAdaptor::Complete(const QString & path, const QString & address)
00113 {
00114 kDebug() << k_funcinfo;
00115 Q_UNUSED(path)
00116 if (security) {
00117 security->complete(address);
00118 }
00119 }
00120
00121 void BluezBluetoothSecurityPasskeyAgentAdaptor::Cancel(const QString & path, const QString & address)
00122 {
00123 kDebug() << k_funcinfo;
00124 Q_UNUSED(path)
00125 if (security) {
00126 security->cancel(address);
00127 }
00128 }
00129
00130 void BluezBluetoothSecurityPasskeyAgentAdaptor::Release()
00131 {
00132 kDebug() << k_funcinfo;
00133 }
00134
00135
00136 BluezBluetoothSecurityAuthorizationAgentAdaptor::BluezBluetoothSecurityAuthorizationAgentAdaptor(BluezBluetoothSecurity * security)
00137 :QDBusAbstractAdaptor(security),security(security),conn(QDBusConnection::systemBus())
00138 {
00139 serviceName = QString("/org/kde/solid/BluezBluetoothSecurityAuthorizationAgentAdaptor%1").arg(time(NULL));
00140 bool done = conn.registerObject(
00141 serviceName,security,QDBusConnection::ExportAdaptors);
00142 if (!done) {
00143 kDebug() << "Failed to register the object: " << conn.lastError().name() << " : " << conn.lastError().message();
00144 serviceName = "";
00145 } else {
00146 kDebug() << "DBus service registered at "<< serviceName <<endl;
00147
00148 QDBusInterface iface("org.bluez", "/org/bluez","org.bluez.Security",conn, this);
00149 iface.call("RegisterDefaultAuthorizationAgent",serviceName);
00150 if (iface.lastError().isValid()) {
00151 kDebug() << "RegisterDefaultAuthorizationAgent failed :" << iface.lastError().name() << " : " << iface.lastError().message();
00152 serviceName = "";
00153 } else {
00154 kDebug() << "RegisterDefaultAuthorizationAgent succesfull!";
00155 }
00156 }
00157
00158 }
00159 BluezBluetoothSecurityAuthorizationAgentAdaptor::~ BluezBluetoothSecurityAuthorizationAgentAdaptor()
00160 {
00161 kDebug() << k_funcinfo;
00162 if (!serviceName.isEmpty())
00163 {
00164 QDBusInterface iface("org.bluez", "/org/bluez","org.bluez.Security",conn, this);
00165 iface.call("UnregisterDefaultAuthorizationAgent",serviceName);
00166 if (iface.lastError().isValid()) {
00167 kDebug() << "UnregisterDefaultAuthorizationAgent failed :" << iface.lastError().name() << " : " << iface.lastError().message();
00168 serviceName = "";
00169 } else {
00170 kDebug() << "UnregisterDefaultAuthorizationAgent Successful!:" << iface.lastError().name() << " : " << iface.lastError().message();
00171 }
00172 }
00173 }
00174
00175 void BluezBluetoothSecurityAuthorizationAgentAdaptor::Authorize(const QString & adapter_path, const QString & address, const QString & service_path, const QString & uuid,const QDBusMessage &msg)
00176 {
00177 kDebug() << k_funcinfo;
00178 Q_UNUSED(service_path)
00179 if (security) {
00180 if(security->authorize(adapter_path,address,uuid)) {
00181 kDebug() << "Service with uuid "<< uuid <<" for " << address << " authorized";
00182 } else {
00183 QDBusMessage error = msg.createErrorReply("org.bluez.Error.Rejected","Authorization request rejected");
00184 QDBusConnection::systemBus().send(error);
00185 }
00186 }
00187 }
00188
00189 void BluezBluetoothSecurityAuthorizationAgentAdaptor::Cancel(const QString & adapter_path, const QString & address, const QString & service_path, const QString & uuid)
00190 {
00191 Q_UNUSED(service_path)
00192 if (security) {
00193 security->cancel(adapter_path,address,uuid);
00194 }
00195 }
00196
00197 void BluezBluetoothSecurityAuthorizationAgentAdaptor::Release()
00198 {
00199 kDebug() << k_funcinfo;
00200 }
00201
00202 #include "bluez-bluetoothsecurityadaptor.moc"