BluetoothConvergenceLayer.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2006 Baylor University
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef _BLUETOOTH_CONVERGENCE_LAYER_
00018 #define _BLUETOOTH_CONVERGENCE_LAYER_
00019 
00020 #include <config.h>
00021 
00022 #ifdef OASYS_BLUETOOTH_ENABLED
00023 
00024 #include <errno.h>
00025 extern int errno;
00026 
00027 #include <oasys/bluez/BluetoothInquiry.h>
00028 #include <oasys/bluez/RFCOMMClient.h>
00029 #include <oasys/bluez/RFCOMMServer.h>
00030 
00031 #include "ConnectionConvergenceLayer.h"
00032 #include "StreamConvergenceLayer.h"
00033 
00034 namespace dtn {
00035 
00036 class BluetoothAnnounce;
00037 
00041 class BluetoothConvergenceLayer : public StreamConvergenceLayer {
00042 public:
00043 
00047     static const u_int8_t BTCL_VERSION = 0x3; // parallels TCPCL
00048 
00052     static const u_int8_t BTCL_DEFAULT_CHANNEL = 10;
00053 
00057     BluetoothConvergenceLayer();
00058 
00060     bool interface_up(Interface* iface, int argc, const char* argv[]);
00061     bool interface_down(Interface* iface);
00062     void dump_interface(Interface* iface, oasys::StringBuffer* buf);
00064 
00068     class BluetoothLinkParams : public StreamLinkParams {
00069     public:
00073         virtual void serialize( oasys::SerializeAction*a );
00074 
00075         bdaddr_t local_addr_;  
00076         bdaddr_t remote_addr_; 
00077         u_int8_t channel_;     
00078     protected:
00079         // See comment in LinkParams for why this is protected
00080         BluetoothLinkParams(bool init_defaults);
00081         friend class BluetoothConvergenceLayer;
00082     };
00083 
00087     static BluetoothLinkParams default_link_params_;
00088 
00089 protected:
00090     friend class BluetoothAnnounce;
00091 
00093     bool set_link_defaults(int argc, const char* argv[],
00094                            const char** invalidp);
00095     void dump_link(Link* link, oasys::StringBuffer* buf);
00097 
00099     virtual LinkParams* new_link_params();
00100     virtual bool parse_link_params(LinkParams* params, int argc,
00101                                    const char** argv,
00102                                    const char** invalidp);
00103     virtual bool parse_nexthop(Link* link, LinkParams* params);
00104     virtual CLConnection* new_connection(LinkParams* params);
00106 
00111     class Listener : public CLInfo, public oasys::RFCOMMServerThread {
00112     public:
00113         Listener(BluetoothConvergenceLayer* cl);
00114         void accepted(int fd, bdaddr_t addr, u_int8_t channel);
00115 
00117         BluetoothConvergenceLayer* cl_;
00118     };
00119 
00124     class Connection : public StreamConvergenceLayer::Connection {
00125     public:
00129         Connection(BluetoothConvergenceLayer* cl,
00130                    BluetoothLinkParams* params);
00131 
00135         Connection(BluetoothConvergenceLayer* cl,
00136                    BluetoothLinkParams* params,
00137                    int fd, bdaddr_t addr, u_int8_t channel);
00138 
00139         virtual ~Connection();
00140 
00141     protected:
00142 
00144         virtual void connect();
00145         virtual void accept();
00146         virtual void disconnect();
00147         virtual void initialize_pollfds();
00148         virtual void handle_poll_activity();
00150 
00152         void send_data();
00154 
00155         void recv_data();
00156         bool recv_contact_header(int timeout);
00157         bool send_bundle(Bundle* bundle);
00158         bool recv_bundle();
00159         bool handle_reply();
00160         int handle_ack();
00161         bool send_ack(u_int32_t bundle_id, size_t acked_len);
00162         bool send_keepalive();
00163 
00168         BluetoothLinkParams* bt_lparams()
00169         {
00170             BluetoothLinkParams* ret =
00171                 dynamic_cast<BluetoothLinkParams*>(params_);
00172             ASSERT(ret != NULL);
00173             return ret;
00174         }
00175 
00176         oasys::RFCOMMClient*  sock_;        
00177         struct pollfd*        sock_pollfd_; 
00178     };
00179 
00180 }; // BluetoothConvergenceLayer
00181 
00182 } // namespace dtn
00183 
00184 #endif // OASYS_BLUETOOTH_ENABLED
00185 #endif // _BLUETOOTH_CONVERGENCE_LAYER_

Generated on Thu Jun 7 16:56:48 2007 for DTN Reference Implementation by  doxygen 1.5.1