00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _BLUETOOTH_CONVERGENCE_LAYER_
00018 #define _BLUETOOTH_CONVERGENCE_LAYER_
00019
00020 #ifndef DTN_CONFIG_STATE
00021 #error "MUST INCLUDE dtn-config.h before including this file"
00022 #endif
00023
00024 #ifdef OASYS_BLUETOOTH_ENABLED
00025
00026 #include <errno.h>
00027 extern int errno;
00028
00029 #include <oasys/bluez/BluetoothInquiry.h>
00030 #include <oasys/bluez/RFCOMMClient.h>
00031 #include <oasys/bluez/RFCOMMServer.h>
00032
00033 #include "ConnectionConvergenceLayer.h"
00034 #include "StreamConvergenceLayer.h"
00035
00036 namespace dtn {
00037
00038 class BluetoothAnnounce;
00039
00043 class BluetoothConvergenceLayer : public StreamConvergenceLayer {
00044 public:
00045
00049 static const u_int8_t BTCL_VERSION = 0x3;
00050
00054 static const u_int8_t BTCL_DEFAULT_CHANNEL = 10;
00055
00059 BluetoothConvergenceLayer();
00060
00062 bool interface_up(Interface* iface, int argc, const char* argv[]);
00063 bool interface_down(Interface* iface);
00064 void dump_interface(Interface* iface, oasys::StringBuffer* buf);
00066
00070 class BluetoothLinkParams : public StreamLinkParams {
00071 public:
00075 virtual void serialize( oasys::SerializeAction*a );
00076
00077 bdaddr_t local_addr_;
00078 bdaddr_t remote_addr_;
00079 u_int8_t channel_;
00080 protected:
00081
00082 BluetoothLinkParams(bool init_defaults);
00083 friend class BluetoothConvergenceLayer;
00084 };
00085
00089 static BluetoothLinkParams default_link_params_;
00090
00091 protected:
00092 friend class BluetoothAnnounce;
00093
00095 bool set_link_defaults(int argc, const char* argv[],
00096 const char** invalidp);
00097 void dump_link(const LinkRef& link, oasys::StringBuffer* buf);
00099
00101 virtual LinkParams* new_link_params();
00102 virtual bool parse_link_params(LinkParams* params, int argc,
00103 const char** argv,
00104 const char** invalidp);
00105 virtual bool parse_nexthop(const LinkRef& link, LinkParams* params);
00106 virtual CLConnection* new_connection(const LinkRef& link,
00107 LinkParams* params);
00109
00114 class Listener : public CLInfo, public oasys::RFCOMMServerThread {
00115 public:
00116 Listener(BluetoothConvergenceLayer* cl);
00117 void accepted(int fd, bdaddr_t addr, u_int8_t channel);
00118
00120 BluetoothConvergenceLayer* cl_;
00121 };
00122
00127 class Connection : public StreamConvergenceLayer::Connection {
00128 public:
00132 Connection(BluetoothConvergenceLayer* cl,
00133 BluetoothLinkParams* params);
00134
00138 Connection(BluetoothConvergenceLayer* cl,
00139 BluetoothLinkParams* params,
00140 int fd, bdaddr_t addr, u_int8_t channel);
00141
00142 virtual ~Connection();
00143
00144 protected:
00145
00147 virtual void connect();
00148 virtual void accept();
00149 virtual void disconnect();
00150 virtual void initialize_pollfds();
00151 virtual void handle_poll_activity();
00153
00155 void send_data();
00157
00158 void recv_data();
00159
00164 BluetoothLinkParams* bt_lparams()
00165 {
00166 BluetoothLinkParams* ret =
00167 dynamic_cast<BluetoothLinkParams*>(params_);
00168 ASSERT(ret != NULL);
00169 return ret;
00170 }
00171
00172 oasys::RFCOMMClient* sock_;
00173 struct pollfd* sock_pollfd_;
00174 };
00175
00176 };
00177
00178 }
00179
00180 #endif // OASYS_BLUETOOTH_ENABLED
00181 #endif // _BLUETOOTH_CONVERGENCE_LAYER_