00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <config.h>
00018
00019 #ifdef OASYS_BLUETOOTH_ENABLED
00020
00021 #include <oasys/util/OptParser.h>
00022 #include <oasys/bluez/Bluetooth.h>
00023 #include "contacts/ContactManager.h"
00024 #include "bundling/BundleDaemon.h"
00025 #include "conv_layers/BluetoothConvergenceLayer.h"
00026
00027 #include "BluetoothAnnounce.h"
00028
00029 namespace dtn {
00030
00031 BluetoothAnnounce::BluetoothAnnounce()
00032 : sdp_reg_(BundleDaemon::instance()->local_eid().c_str())
00033 {
00034 oasys::Bluetooth::hci_get_bdaddr(&cl_addr_);
00035 }
00036
00037 bool
00038 BluetoothAnnounce::configure(const std::string& name, ConvergenceLayer* cl,
00039 int argc, const char* argv[])
00040 {
00041 cl_ = cl;
00042 name_ = name;
00043 type_.assign(cl->name());
00044
00045 oasys::OptParser p;
00046 p.addopt(new oasys::BdAddrOpt("cl_addr",&cl_addr_));
00047 bool setinterval = false;
00048 p.addopt(new oasys::UIntOpt("interval",&interval_,"","",&setinterval));
00049 cl_channel_ = BluetoothConvergenceLayer::BTCL_DEFAULT_CHANNEL;
00050
00051 const char* invalid;
00052 if (! p.parse(argc, argv, &invalid))
00053 {
00054 log_err("bad parameter %s",invalid);
00055 return false;
00056 }
00057
00058 if (! setinterval)
00059 {
00060 log_err("required parameter missing: interval");
00061 return false;
00062 }
00063 else
00064 {
00065
00066 interval_ *= 1000;
00067 }
00068
00069 local_.assign(bd2str(cl_addr_));
00070 return true;
00071 }
00072
00073 size_t
00074 BluetoothAnnounce::format_advertisement(u_char*,size_t)
00075 {
00076 return 0;
00077 }
00078
00079 void
00080 BluetoothAnnounce::handle_neighbor_discovered(const std::string& nexthop,
00081 const EndpointID& remote_eid)
00082 {
00083 (void)remote_eid;
00084 (void)nexthop;
00085 bdaddr_t remote_addr;
00086 oasys::Bluetooth::strtoba(nexthop.c_str(),&remote_addr);
00087
00088 ASSERT(type() == "bt");
00089
00090 ContactManager* cm = BundleDaemon::instance()->contactmgr();
00091 Link* link = cm->find_link_to(cl_, "", remote_eid);
00092 if (link != NULL)
00093 return;
00094
00095 BluetoothConvergenceLayer* btcl =
00096 dynamic_cast<BluetoothConvergenceLayer*>(cl_);
00097
00098 BluetoothConvergenceLayer::BluetoothLinkParams* params =
00099 dynamic_cast<BluetoothConvergenceLayer::BluetoothLinkParams*>
00100 (btcl->new_link_params());
00101
00102 bacpy(¶ms->remote_addr_,&remote_addr);
00103
00104 CLConnection* conn = btcl->new_connection(params);
00105 conn->start();
00106 }
00107
00108 }
00109
00110 #endif // OASYS_BLUETOOTH_ENABLED