00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef PANCONNECTION_H
00017 #define PANCONNECTION_H
00018
00019
00020 #include <e32base.h>
00021 #include <e32cons.h>
00022 #include <bt_sock.h>
00023 #include <es_sock.h>
00024 #include <in_sock.h>
00025 #include <btsdp.h>
00026
00027
00028 enum TSide
00029 {
00030 ELocalRole,
00031 EPeerRole
00032 };
00033
00034
00035
00036 const TInt KIpUUID = 0x0009;
00037 const TInt KTcpUUID = 0x0004;
00038
00039
00040 static const TSdpAttributeID KSdpAttrIdServiceDescription
00041 = KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetServiceDescription;
00042
00043 static const TSdpAttributeID KSdpAttrIdServiceName
00044 = KSdpAttrIdBasePrimaryLanguage + KSdpAttrIdOffsetServiceName;
00045
00046 _LIT(KServiceName, "PAN Profile Engine");
00047 _LIT(KServiceDescription, "This device is ready to use PAN profile");
00048
00056 class CPanConnections : public CActive
00057 {
00058 public:
00059 static CPanConnections* NewL(CConsoleBase & aConsole);
00060
00061 ~CPanConnections();
00062 void CancelRecvFrom();
00063 TInt StartConnection(TBTDevAddr* aDevAddr, TBool aUsePANNotifier, TBool aUseTcpTransport);
00064 TInt StopConnection();
00065 TInt SetActivePanConn(TUint aConnIndex);
00066 void SetLocalIpAddrL(TUint32 aAddr);
00067 void SetFixedRoleL(TSide aSide, TUint aRole);
00068 void PrintConns();
00069 TInt TcpIpBindAndListen();
00070 TInt TcpIpBindAndConnect();
00071 void ListenDoCancel();
00072 void ConnectDoCancel();
00073 TInt CloseTcpIpSocketConnect();
00074 TUint32 GetRemoteIpAddr() const;
00075 void SetRemoteIpAddr(TUint32 aAddr);
00076 TInt AcceptNewSocket();
00077 void PrintTcpSocketConnections();
00078 TInt GetLocalRole() const;
00079 void CancelIap();
00080 TInt StopIAP();
00081 TInt CloseAllTcpIpSockets();
00082 TInt CloseCurrentTcpIpSocket();
00083 TInt ActiveConnCount();
00084 void CancelAllOperations();
00085 TInt UdpBind();
00086 void RunL();
00087 void DoCancel();
00088
00089 RArray<TInetAddr>& RemoteNames();
00090 RSocket& GetSocket();
00091 RArray<RSocket>& GetSocketArray();
00092
00093 private:
00094 CPanConnections(CConsoleBase & aConsole);
00095 void SetTransportLayerProtocol(TUint aProtocol);
00096 void IapStarted();
00097 void TcpIpConnectionComplete();
00098 void TcpIpListenComplete();
00099 TInt StartIAP();
00100 void PrintIAPL();
00101 TInt UpdateCurrentConnections();
00102 TInt Initialise();
00103 TUint32 GetLocalIpAddr();
00104 void ConfigureIAPL(TBool aIsListening, TBTDevAddr* aDevAddr, TBool aUsePANNotifier);
00105 void RecvTcpIpPacket();
00106 void RegisterSdpL();
00107 void ReceiveRemoteName();
00108
00109 public:
00110 TBool iIapStarted;
00111 TBool iIapLoading;
00112 TBool iListening;
00113
00114 private:
00115 enum TActiveMode
00116 {
00117 EIAPStart,
00118 ESocketAccept,
00119 ESocketConnect,
00120 EUdpReceive
00121 };
00122
00123
00124 enum PanProfileIAPs
00125 {
00126 EGeneralIAP = 1,
00127 EUnknownConnUnknownRolesListen,
00128 EUnknownConnUnknownRoles,
00129 EKnownConnUnknownRolesListen
00130 };
00131
00132 RSocket iSocket;
00133 RArray<RSocket> iSocketArray;
00134 TInt iActiveTcpSocket;
00135 TPckgBuf<TInt> iBuff;
00136 TInetAddr iSrcAddr;
00137 TInetAddr iDstAddr;
00138 TUint iLocalRole;
00139 TUint iPeerRole;
00140 TBool iUseTcpTransport;
00141 TActiveMode iActiveMode;
00142 TBTDevAddr iControlAddr;
00143 TInt iActivePanConn;
00144 RConnection iConnection;
00145 RSocketServ iSockSvr;
00146 CConsoleBase& iConsole;
00147 RBTDevAddrArray iActiveConnections;
00148 TUint32 iRemoteIpAddr;
00149 TUint32 iLocalIpAddr;
00150 RSdp iSdp;
00151 RSdpDatabase iSdpdb;
00152 TInetAddr iRemoteName;
00153 RArray<TInetAddr> iRemoteNames;
00154
00155 };
00156
00157
00158 #endif // PANCONNECTION_H