Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

bnep.h

Go to the documentation of this file.
00001 // GENERAL PUBLIC LICENSE AGREEMENT
00002 // 
00003 // PLEASE READ THIS DOCUMENT CAREFULLY BEFORE UTILIZING THE PROGRAM
00004 // 
00005 // BY UTILIZING THIS PROGRAM, YOU AGREE TO BECOME BOUND BY THE TERMS OF
00006 // THIS LICENSE.  IF YOU DO NOT AGREE TO THE TERMS OF THIS LICENSE, DO
00007 // NOT USE THIS PROGRAM OR ANY PORTION THEREOF IN ANY FORM OR MANNER.
00008 // 
00009 // This Program is licensed, not sold to you by GEORGIA TECH RESEARCH
00010 // CORPORATION ("GTRC"), owner of all code and accompanying documentation
00011 // (hereinafter "Program"), for use only under the terms of this License,
00012 // and GTRC reserves any rights not expressly granted to you.
00013 // 
00014 // 1.  This License allows you to:
00015 // 
00016 // (a) make copies and distribute copies of the Program's source code
00017 // provide that any such copy clearly displays any and all appropriate
00018 // copyright notices and disclaimer of warranty as set forth in Article 5
00019 // and 6 of this License.  All notices that refer to this License and to
00020 // the absence of any warranty must be kept intact at all times.  A copy
00021 // of this License must accompany any and all copies of the Program
00022 // distributed to third parties.
00023 // 
00024 // A fee may be charged to cover the cost associated with the physical
00025 // act of transferring a copy to a third party.  At no time shall the
00026 // program be sold for commercial gain either alone or incorporated with
00027 // other program(s) without entering into a separate agreement with GTRC.
00028 //  
00029 // 
00030 // (b) modify the original copy or copies of the Program or any portion
00031 // thereof ("Modification(s)").  Modifications may be copied and
00032 // distributed under the terms and conditions as set forth above,
00033 // provided the following conditions are met:
00034 // 
00035 //     i) any and all modified files must be affixed with prominent
00036 // notices that you have changed the files and the date that the changes
00037 // occurred.
00038 //              
00039 //     ii) any work that you distribute, publish, or make available, that
00040 // in whole or in part contains portions of the Program or derivative
00041 // work thereof, must be licensed at no charge to all third parties under
00042 // the terms of this License.
00043 // 
00044 //    iii) if the modified program normally reads commands interactively
00045 // when run, you must cause it, when started running for such interactive
00046 // use in the most ordinary way, to display and/or print an announcement
00047 // with all appropriate copyright notices and disclaimer of warranty as
00048 // set forth in Article 5 and 6 of this License to be clearly displayed.
00049 // In addition, you must provide reasonable access to this License to the
00050 // user.
00051 // 
00052 // Any portion of a Modification that can be reasonably considered
00053 // independent of the Program and separate work in and of itself is not
00054 // subject to the terms and conditions set forth in this License as long
00055 // as it is not distributed with the Program or any portion thereof.
00056 // 
00057 // 
00058 // 2. This License further allows you to copy and distribute the Program
00059 //    or a work based on it, as set forth in Article 1 Section b in
00060 //    object code or executable form under the terms of Article 1 above
00061 //    provided that you also either:
00062 // 
00063 //    i) accompany it with complete corresponding machine-readable source
00064 // code, which must be distributed under the terms of Article 1, on a
00065 // medium customarily used for software interchange; or,
00066 // 
00067 //   ii) accompany it with a written offer, valid for no less than three
00068 // (3) years from the time of distribution, to give any third party, for
00069 // no consideration greater than the cost of physical transfer, a
00070 // complete machine-readable copy of the corresponding source code, to be
00071 // distributed under the terms of Article 1 on a medium customarily used
00072 // for software interchange; or,
00073 // 
00074 // 
00075 // 3.  Export Law Assurance.
00076 // 
00077 // You agree that the Software will not be shipped, transferred or
00078 // exported, directly into any country prohibited by the United States
00079 // Export Administration Act and the regulations thereunder nor will be
00080 // used for any purpose prohibited by the Act.
00081 //  
00082 // 4.  Termination.
00083 // 
00084 // If at anytime you are unable to comply with any portion of this
00085 // License you must immediately cease use of the Program and all
00086 // distribution activities involving the Program or any portion thereof.
00087 // 
00088 // 
00089 // 5.  Disclaimer of Warranties and Limitation on Liability.
00090 // 
00091 // YOU ACCEPT THE PROGRAM ON AN "AS IS" BASIS.  GTRC MAKES NO WARRANTY
00092 // THAT ALL ERRORS CAN BE OR HAVE BEEN ELIMINATED FROM PROGRAM.  GTRC
00093 // SHALL NOT BE RESPONSIBLE FOR LOSSES OF ANY KIND RESULTING FROM THE USE
00094 // OF PROGRAM AND ITS ACCOMPANYING DOCUMENT(S), AND CAN IN NO WAY PROVIDE
00095 // COMPENSATION FOR ANY LOSSES SUSTAINED, INCLUDING BUT NOT LIMITED TO
00096 // ANY OBLIGATION, LIABILITY, RIGHT, CLAIM OR REMEDY FOR TORT, OR FOR ANY
00097 // ACTUAL OR ALLEGED INFRINGEMENT OF PATENTS, COPYRIGHTS, TRADE SECRETS,
00098 // OR SIMILAR RIGHTS OF THIRD PARTIES, NOR ANY BUSINESS EXPENSE, MACHINE
00099 // DOWNTIME OR DAMAGES CAUSED TO YOU BY ANY DEFICIENCY, DEFECT OR ERROR
00100 // IN PROGRAM OR MALFUNCTION THEREOF, NOR ANY INCIDENTAL OR CONSEQUENTIAL
00101 // DAMAGES, HOWEVER CAUSED.  GTRC DISCLAIMS ALL WARRANTIES, BOTH EXPRESS
00102 // AND IMPLIED RESPECTING THE USE AND OPERATION OF PROGRAM AND ITS
00103 // ACCOMPANYING DOCUMENTATION, INCLUDING ALL IMPLIED WARRANTIES OF
00104 // MERCHANTABILITY AND FITNESS FOR PARTICULAR PURPOSE AND ANY IMPLIED
00105 // WARRANTY ARISING FROM COURSE OF PERFORMANCE, COURSE OF DEALING OR
00106 // USAGE OF TRADE.  GTRC MAKES NO WARRANTY THAT PROGRAM IS ADEQUATELY OR
00107 // COMPLETELY DESCRIBED IN, OR BEHAVES IN ACCORDANCE WITH ANY
00108 // ACCOMPANYING DOCUMENTATION.  THE USER OF PROGRAM IS EXPECTED TO MAKE
00109 // THE FINAL EVALUATION OF PROGRAM'S USEFULNESS IN USER'S OWN
00110 // ENVIRONMENT.
00111 // 
00112 // GTRC represents that, to the best of its knowledge, the software
00113 // furnished hereunder does not infringe any copyright or patent.
00114 // 
00115 // GTRC shall have no obligation for support or maintenance of Program.
00116 // 
00117 // 6.  Copyright Notice.
00118 // 
00119 // THE SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE COPYRIGHTED WITH ALL
00120 // RIGHTS RESERVED BY GTRC.  UNDER UNITED STATES COPYRIGHT LAWS, THE
00121 // SOFTWARE AND ITS ACCOMPANYING DOCUMENTATION MAY NOT BE COPIED EXCEPT
00122 // AS GRANTED HEREIN.
00123 // 
00124 // You acknowledge that GTRC is the sole owner of Program, including all
00125 // copyrights subsisting therein.  Any and all copies or partial copies
00126 // of Program made by you shall bear the copyright notice set forth below
00127 // and affixed to the original version or such other notice as GTRC shall
00128 // designate.  Such notice shall also be affixed to all improvements or
00129 // enhancements of Program made by you or portions thereof in such a
00130 // manner and location as to give reasonable notice of GTRC's copyright
00131 // as set forth in Article 1.
00132 // 
00133 // Said copyright notice shall read as follows:
00134 // 
00135 // Copyright 2004
00136 // Dr. George F. Riley
00137 // Georgia Tech Research Corporation
00138 // Atlanta, Georgia 30332-0415
00139 // All Rights Reserved
00140 //
00141 
00142 
00143 // Georgia Tech Network Simulator - Bluetooth BNEP class
00144 // George F. Riley, Georgia Tech, Spring 2004
00145 
00146 #ifndef __bnep_h
00147 #define __bnep_h
00148 
00149 //
00150 // Bluetooth Network Encapsulation Protocol 
00151 // (BNEP) 1.0 
00152 //
00153 #include "timer.h"
00154 #include "bluetus.h"
00155 #include "l2cap.h"
00156 #include "application-blue.h"
00157 #include "common-defs.h"
00158 
00159 //define the BNEP Type values
00160 #define BNEP_GENERAL_ETHERNET                                   0x00
00161 #define BNEP_CONTROL                                                    0x01
00162 #define BNEP_COMPRESSED_ETHERNET                                0x02
00163 #define BNEP_COMPRESSED_ETHERNET_SOURCE_ONLY    0x03
00164 #define BNEP_COMPRESSED_ETHERNET_DST_ONLY               0x04
00165 
00166 //define BNEP control type value
00167 #define BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD             0x00
00168 #define BNEP_SETUP_CONNECTION_REQUEST_MSG               0x01
00169 #define BNEP_SETUP_CONNECTION_RESPONSE_MSG              0x02
00170 #define BNEP_FILTER_NET_TYPE_SET_MSG                    0x03
00171 #define BNEP_FILTER_NET_TYPE_RESPONSE_MSG               0x04
00172 #define BNEP_FILTER_MULTI_ADDR_SET_MSG                  0x05
00173 #define BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG             0x06
00174 
00175 class BlueApplication;
00176 
00177 struct BNEPPacket {
00178         uChar ucType_E;
00179                 //7 bits Type followed by E flag
00180         uChar ucPayload[0];
00181 };
00182 
00183 //BNEP General Ethernet Packet header.
00184 struct BNEP_ETHERNET_Hdr {
00185         uChar  ucType_E;
00186         BdAddr Dst;
00187         BdAddr Src;
00188         uShort usProtocolType; /* Networking Protocol Type*/
00189         uChar ucPayload[0];
00190 
00191         uShort HdrSize() {
00192                 return sizeof(uChar) + 2*sizeof(BdAddr) + sizeof(uShort);
00193         }
00194         //extension header or Payload
00195 };
00196 
00198 // BNEP control message format
00200 //
00201 //BNEP Control Packet header
00202 struct BNEP_CONTROL_Hdr {
00203         uChar ucType_E;
00204         uChar ucCtrlType;
00205 };
00206 
00207 struct BNEP_CNU_Packet { //Command Not Understand == "CNU"
00208         BNEP_CONTROL_Hdr CtrlHdr;
00209         uChar ucUCType; //Unkown Control Type
00210 };
00211 
00212 //response format for all kinds of request:
00213 struct BNEP_RSP_Packet {
00214         BNEP_CONTROL_Hdr CtrlHdr;
00215         //extension may exist here.
00216         uShort usResponse;
00217 };
00218         
00219 struct BNEP_SCReqM_Packet { //Setup_Connection_Request_Msg == "SCRM"
00220         BNEP_CONTROL_Hdr CtrlHdr;
00221         //here may contains extension header based on flag "E".
00222         uChar ucUUIDSize; //ucUUIDSize = N
00223 
00224         uChar ucPayload[0]; //contains DstUUID and SrcUUID
00225         //uChar *pDstUUID;  //0---N
00226         //uChar *pSrcUUID;  //0---N
00227 };
00228 
00229 struct ProtocolStartEnd {
00230         uShort usTypeRangeStart;
00231         uShort usTypeRangeEnd;
00232 };
00233 struct BNEP_FNTSM_Packet { //Filter_Net_Type_Set_Msg = "FNTSM"
00234         BNEP_CONTROL_Hdr CtrlHdr;
00235         uShort usLength;
00236         ProtocolStartEnd *pStartEnd;
00237 };
00238 
00239 struct MultiAddrStartEnd {
00240         //MACAddr AddrStart;
00241         //MACAddr AddrEnd;
00242         uShort AddrStart;
00243         uShort AddrEnd;
00244 };
00245 struct BNEP_FMASM_Packet { //Filer_Multi_Addr_Set_Msg = "FMASM"
00246         BNEP_CONTROL_Hdr CtrlHdr;
00247         //optionally here contains extension
00248         uShort usLength;
00249         MultiAddrStartEnd *pAddrStartEnd;
00250 };
00251 
00252 
00253 //BNEP Compressed Ethernet Packet header
00254 struct BNEP_COMPRESSED_ETHERNET_Hdr {
00255         uChar ucType_E;
00256         uShort usProtocolType; /* Networking Protocol Type*/
00257 
00258         uShort HdrSize() {
00259                 return sizeof(uChar) + sizeof(uShort);
00260         }
00261 
00262         //extension header or Payload.
00263         uChar ucPayload[0];     
00264 };
00265 
00266 //BNEP Compressed Ethernet source only packet header
00267 struct BNEP_COMPRESSED_ETHERNET_SRC_ONLY_Hdr {
00268         uChar ucType_E;
00269         BdAddr Src;
00270         uShort usProtocolType;
00271         
00272         uShort HdrSize() {
00273                 return sizeof(uChar) + sizeof(BdAddr) + sizeof(uShort);
00274         }
00275         //extension header or Payload
00276         uChar ucPayload[0];     
00277 };
00278 
00279 //BNEP Compressed Ethernet Dest only packet header
00280 struct BNEP_COMPRESSED_ETHERNET_DST_ONLY_Hdr {
00281         uChar ucType_E;
00282         BdAddr Dst;
00283         uShort usProtocolType;
00284 
00285         uShort HdrSize() {
00286                 return sizeof(uChar) + sizeof(BdAddr) + sizeof(uShort);
00287         }
00288         //extension header or Payload
00289         uChar ucPayload[0];     
00290 };
00291 
00293 //Extension header
00295 
00296 //BNEP Extension header
00297 struct BNEP_EXTENSION_Hdr{
00298         uChar ucType_E;
00299         uChar ucLength;
00300         //extension payload
00301 };
00302 
00303 #define BNEP_EXTENSION_CONTROL  0x00
00304 
00305 //BNEP Extension control packet header
00306 struct BNEP_EXTENSION_CONTROL_Hdr {
00307         uChar ucType_E;
00308         uChar ucLength;
00309         uChar ucCtlType;
00310         //control packet based on Control Type.
00311 };
00312 
00313 //Timer events
00314 class BNEPTimerEvent : public TimerEvent {
00315     public:
00316     // the types of the BNEP timer events
00317           typedef enum {CONNREQ_TIMEOUT, FILTERREQ_TIMEOUT
00318                          } BNEPTimerEvent_t;
00319     public:
00320            BNEPTimerEvent(Event_t ev) 
00321                  : TimerEvent(ev) { } 
00322                virtual ~BNEPTimerEvent() {}
00323 };
00324 
00325 class L2cap;
00326 
00327 // Define the start/stop events
00328 class BnepEvent : public Event {
00329 public:
00330   typedef enum { STARTB, STOPB, STARTBM } BnepEvent_t;
00331   BnepEvent() { }
00332   BnepEvent(Event_t ev) : Event(ev) { }
00333 };
00334 
00335 class Bnep : public TimerHandler , public Handler{
00336         public:
00337                 //constructor
00338                 Bnep(L2cap *pL2cap);
00339                 //copy constructor
00340                 //Bnep* Copy() const;
00341                 //destructor.
00342                 virtual ~Bnep();
00343                 uShort PSM() {
00344                         return 0x000F; //BNEP;
00345                 }
00346         public:
00347                 //test method for lower layer, it will continuing sending data
00348                 BdAddr dst;
00349                 void TestL2CAP(BdAddr dst);
00350                 void Start(Time_t t, BdAddr dst);
00351                 void Stop(Time_t t);
00352                 void Handle(Event *e, Time_t);
00353                 //end of test
00354 
00355                 //Connection management
00356                 void AttachApplication(BlueApplication* a) { pApplication = a;}
00357                 
00358                 void SetupConnReq(uChar ucUUIDSize, uChar *pDstUUID,
00359                                                 uChar *pSrcUUID);
00360                 uShort RecvConnRsp(BNEPPacket *pPacket);
00361         uShort RecvConnReq(BNEPPacket *pPkt);
00362                 uShort SendRsp(bool bE, uChar ucCtrlType, uShort usExtLen, 
00363                                                 void * pExt, uShort usResponse);
00364                 
00365                 void RecvControlPacket(BNEPPacket *pPacket);                      
00366                 
00367                 uShort SendFilterNetSet(bool bE, uShort usListLength, void * pExt, 
00368                                                 void* NetStartEnd);
00369                 uShort RecvReqFilterNetSet(BNEPPacket *pPkt);
00370                 uShort RecvRspFilterNet(BNEPPacket *pPkt);
00371                 uShort SendFilterMultiAddrSet(bool bE, uShort usListLength, 
00372                                                 void * pExt,  void* MultiAddrStartEnd);
00373                 uShort RecvReqFilterMultiAddrSet(BNEPPacket *pPkt);
00374                 uShort RecvRspFilterMultiAddr(BNEPPacket *pPkt);
00375                                                                                                                                            
00376                 
00377         public: 
00378                 uShort DataIndication(void *pPacket, uShort usCID); //channel id
00379         //General version, src and dst address are required
00380                 uShort DataRequest(bool bE, BdAddr Src, BdAddr Dst, uShort 
00381                                                 usProtocolType, uShort usLenExt, 
00382                                                 void * pExt, uShort usLenData, void * pData);
00383                 //compressed version, no address information is required
00384                 uShort DataRequest(bool bE, uShort usProtocolType, uShort 
00385                                                 usLenExt, void * pExt, uShort usLenData, 
00386                                                 void * pData);
00387                 //compressed version, either src or dst is required.
00388                 uShort DataRequest(bool bE, BdAddr Src, uShort usProtocolType,
00389                                            uShort usLenExt, void * pExt, uShort usLenData,
00390                                            void * pData, uChar ucType);
00391                 //application send
00392                 NCount_t Send(Size_t s);
00393                 bool IsConn() {return connected;}
00394                 
00395         public:
00396                 //Signalling Interface to L2CAP layer.
00397                 uShort L2CA_ConnectInd(uShort usPSM, uChar ucIdentifier,
00398                                         uShort usLocalChannelID) ;
00399 
00400                 uShort L2CA_ConnectCfm(uShort usLocalChannelID) ;
00401 
00402                 uShort L2CA_ConnectCfmNeg(uShort usLocalChannelID);
00403                 uShort L2CA_ConnectPnd(uShort usCID) ;
00404 
00405                 uShort L2CA_ConfigInd(uShort usLocalChannelID, uChar ucIdentifier);
00406 
00407                 uShort L2CA_ConfigCfm(uShort usLocalChannelID) ;
00408 
00409                 uShort L2CA_ConfigCfmNeg(uShort usLocalChannelID) ;
00410 
00411                 uShort L2CA_DisconnectInd(uShort usLocalChannelID, 
00412                                 uChar ucIdentifier) ;
00413 
00414                 uShort L2CA_DisconnectCfm() ;
00415                 
00416                 L2cap *pL2CAP;  //change to public for stat output in application
00417                                 
00418         private:
00419                 Timer timer;
00420                 BNEPTimerEvent *pConnReqTimeout;
00421                 BNEPTimerEvent *pFilterReqTimeout; //only one of them exist.
00422 
00423                 //Timer handle methods
00424                 virtual void Timeout(TimerEvent *);
00425                 //Timer management
00426                 void ScheduleTimer(Event_t, BNEPTimerEvent*&, Time_t);
00427                 void CancelTimer(BNEPTimerEvent*&, bool delTimer = false);
00428                 void CancelAllTimers();
00429 
00430         private:
00431                 
00432 #define CLOSED_BNEP             0x00
00433 #define HALF_OPEN_BNEP  0x01 //set after sending SetupConnReq           
00434 #define CONNECTED_BNEP  0x02            
00435                 uChar ucState; 
00436                 //before getting Setup_Connection response successfully
00437                 //usState = CLOSED;
00438                 //
00439                 uChar ucUUIDSize;
00440                 uChar *pSrcUUID;
00441                 uChar *pDstUUID;
00442                 
00443                 uShort usLocalCID;//get this value after you establish L2CAP conn
00444 
00445                 BlueApplication* pApplication;  //Application object
00446                 bool connected;
00447 
00448                 //Add a net type filter list
00449                 
00450                 //Add a multicast address filter list.
00451 
00452 };
00453 
00454 #endif

Generated on Wed Aug 27 16:17:12 2008 for Georgia Tech Network Simulator (GTNetS) by  doxygen 1.3.9.1