1/*
2    File:       IrLSAPConn.h
3
4    Contains:   Methods for implementing IrLSAPConn
5
6*/
7
8
9#ifndef __IRLSAPCONN_H
10#define __IRLSAPCONN_H
11
12#include "IrStream.h"
13#include "IrEvent.h"
14
15// Forward reference
16class TIrGlue;
17class TIrLMP;
18class CBuffer;
19
20// Constants
21
22#define kWatchdogTimeoutCount   30      // Wait for up to 30 secs for conn response
23
24enum LSAPConnStates
25{
26    kLSAPConnDisconnected,
27    kLSAPConnConnectPending,            // Referred to as "SetupPending" in LMP spec
28    kLSAPConnConnect,                   // Referred to as "Setup" in LMP spec
29    kLSAPConnListenPending,
30    kLSAPConnListen,
31    kLSAPConnAccept,
32    kLSAPConnDataTransferReady,
33    kLSAPDisconnectPending              // jdg: new state
34};
35
36enum LMPDUElements
37{
38    kLMPDUControlFlag           = 0x80, // Set on the fDstLSAPId field for non-data events
39    kLMPDUReplyFlag             = 0x80, // Set for connect & access mode replies
40
41    kLMPDUDataEvent             = 0x00,
42
43    kLMPDUConnectRequest        = 0x01,
44    kLMPDUConnectReply          = 0x81,
45
46    kLMPDUDisconnectEvent       = 0x02,
47
48    kLMPDUAccessModeRequest     = 0x03,
49    kLMPDUAccessModeReply       = 0x83
50};
51
52enum LMPDUDisconnectReasons
53{
54    kIrUserRequestedDisconnect  = 0x01,
55    kIrLAPUnexpectedDisconnect  = 0x02,
56    kIrLAPFailedConnection      = 0x03,
57    kIrLAPReset                 = 0x04,
58    kIrLMMuxInitiatedDisconnect = 0x05,
59    kIrDataSentOnDiscLSAPConn   = 0x06,
60    kIrNonResponsiveLMMuxClient = 0x07,
61    kIrNoAvailableLMMuxClient   = 0x08,
62    kIrHalfOpen                 = 0x09,
63    kIrIllegalSourceAddress     = 0x0A
64};
65
66enum LMPDUControlStatusValues
67{
68    kIrLMPDUControlSuccess      = 0x00,
69    kIrLMPDUControlFailure      = 0x01,
70    kIrLMPDUControlUnsupported  = 0xFF
71};
72
73enum LMPDUAccessModes
74{
75    kIrLMPMultiplexedMode       = 0x00,
76    kIrLMPExclusiveMode         = 0x01
77};
78
79
80// Classes
81
82// --------------------------------------------------------------------------------------------------------------------
83//                      TControlPacket
84// --------------------------------------------------------------------------------------------------------------------
85
86class TLMPDUHeader
87{
88    public:
89
90	    UByte           fDstLSAPId;
91	    UByte           fSrcLSAPId;
92	    UByte           fOpCode;
93	    UByte           fInfo;
94	    UByte           fMode;
95};
96
97
98// --------------------------------------------------------------------------------------------------------------------
99//                      TLSAPConn
100// --------------------------------------------------------------------------------------------------------------------
101
102class TLSAPConn : public TIrStream
103{
104	    OSDeclareDefaultStructors(TLSAPConn);
105
106    public:
107	    static TLSAPConn *  tLSAPConn(TIrGlue* irda, TIrStream* client);
108	    Boolean             Init(TIrGlue* irda, TIrStream* client);
109	    void                free(void);
110
111	    void                AssignId(ULong id);
112	    TIrEvent*           GetPendConnLstn();
113	    Boolean             YourData(TLMPDUHeader& header, Boolean justChecking);
114	    void                OneSecTickerComplete();
115	    UByte               GetMyLSAPId();
116
117    private:
118
119	    // TIrStream override
120	    void                NextState(ULong event);
121
122	    void                HandleDisconnectedStateEvent(ULong event);
123	    void                HandleConnectPendingStateEvent(ULong event);
124	    void                HandleConnectStateEvent(ULong event);
125	    void                HandleListenPendingStateEvent(ULong event);
126	    void                HandleListenStateEvent(ULong event);
127	    void                HandleAcceptStateEvent(ULong event);
128	    void                HandleDataTransferReadyStateEvent(ULong event);
129	    void                HandleDisconnectPendingStateEvent(ULong event);
130
131	    void                SaveCurrentRequest();
132	    Boolean             InternalDisconnectRequest();
133	    Boolean             InternalPutRequest();
134	    void                PassRequestToLMP();
135	    void                DisconnectStart(IrDAErr result, TIrDisconnectRequest *discRequest = nil);
136
137	    void                GetControlFrame();
138	    void                PutControlFrame(UByte opCode, UByte info);
139	    void                GetDataFrame(Boolean resend = false);
140	    void                PutDataFrame();
141
142	    void                ConnLstnComplete(IrDAErr result);
143
144	    void                StartConnectTimer();
145	    void                StopConnectTimer();
146
147	    // Fields�
148
149	    UByte               fState;
150	    Boolean             fConnecting;            // vs listening
151
152	    TIrStream*          fClient;                // Upstream client
153
154	    IrDAErr             fResult;                // Pending result for failed connect or listen
155	    TIrEvent*           fPendConnLstn;          // Pending connect, listen request
156	    CBuffer*            fConnLstnUserData;      // Buffer to send/recv out of band data w/connect or listen
157
158	    CBuffer*            fGetData;               // Save get buffer in case resend is required
159	    ULong               fGetOffset;             // Save offset in buffer in case resend is required
160	    ULong               fGetLength;             // Save space available in buffer in case resend is required
161
162	    UByte               fMyLSAPId;
163	    UByte               fPeerLSAPId;
164
165						    // JDG: listen/connect event records smashed!
166	    ULong               fDevAddr;           // jdg: saved fDevAddr from listen complete
167	    UByte               fLSAPId;            // jdg: save  fLSAPId  from listen complete
168
169	    CList               *fPendingRequests;  // jdg: queue requests pending during disconnect
170
171	    Boolean             fWatchdogTimerActive;
172	    UByte               fWatchdogTimerCount;
173
174};
175
176#endif // __IRLSAPCONN_H
177