versadac  1
versadac - Scalable Recorder Firmware
clserver.h
1 /*---------------------------------------------------------------------------*/
2 /* Copyright (C) 2006 Woodhead Software & Electonics. All rights reserved. */
3 /*---------------------------------------------------------------------------*/
4 /* This program is protected by international copyright. */
5 /* */
6 /* The use of this software including but not limited to its Source Code */
7 /* is subject to restrictions as agreed in the license agreement between */
8 /* you and Woodhead. */
9 /* Copying or distribution is not allowed unless expressly permitted */
10 /* according to your license agreement with Woodhead. */
11 /*---------------------------------------------------------------------------*/
12 /* */
13 /* Project : STACK PROFINET Controller */
14 /* Component : RPC Interface */
15 /* $Workfile:: clserver.h $*/
16 /* $Revision:: 2 $*/
17 /* $Date:: 9/22/09 6:01p $*/
18 /* */
19 /*---------------------------------------------------------------------------*/
20 /* */
21 /* D e s c r i p t i o n : */
22 /* RPC Runtime Server State Machine */
23 /* */
24 /*---------------------------------------------------------------------------*/
25 #ifndef __RPC_CLSERVER_H__
26  #define __RPC_CLSERVER_H__
27 
28 #include "os_pck.h"
29 
30 
31 /*---------------------------------------------------------------------------*/
32 /* TIMER MANAGMENT */
33 /*---------------------------------------------------------------------------*/
34 
35 /*List of actual timer index*/
36 #define ID_TIMEOUT_IDLE 0
37 #define ID_TIMEOUT_RESEND 1
38 #define NB_SERVER_TIMER 2
39 APP_WORD rpc_tmIdle (APP_LPVOID lpData, APP_WORD wDummy);
40 APP_WORD rpc_tmResend (APP_LPVOID lpData, APP_WORD wDummy);
41 
42 
43 
44 /*---------------------------------------------------------------------------*/
45 /* VARIABLE */
46 /*---------------------------------------------------------------------------*/
47 
48 typedef struct _CL_SERVER_MACHINE_RT
49 {
50  ST_CLR_RPC_UUID uuidActivityId; /*12 - 0 ACTIVITY_ID */
51  ST_CLR_RPC_UUID uuidObjId; /*12 - 12 OBJ_ID */
52  ST_CLR_RPC_UUID uuidIfId; /*12 - 24 IF_ID */
53  ST_CLR_RPC_UUID uuidClientExContext;/*12 - 36 CLIENT_EXECUTION_CONTEXT */
54  APP_DWORD dwSeqNum; /*4 - 40 SEQ_NUM */
55  APP_DWORD dwIfVersion; /*4 - 44 IF_VERSION */
56  APP_DWORD dwCancelID; /*4 - 48 CANCEL_ID */
57  APP_LPBYTE pbyInParams; /*4 - 52 IN_PARAMS */
58  APP_LPBYTE pbyOutParams; /*4 - 56 OUT_PARAMS */
59  APP_LPBYTE pbyOutFrag; /*4 - 60 OUT_FRAG */
60  APP_LPBYTE pbyBody; /*4 - 64 BODY */
61  APP_WORD wOpNum; /*4 - 68 OP_NUM */
62  APP_WORD wInFragNum; /*2 - 70 IN_FRAG_NUM */
63  APP_WORD wOutFragNum; /*2 - 72 LAST REQ FRAG ACK */
64  APP_WORD wContInFragNum; /*2 - 74 CONT_IN_FRAG_NUM */
65  APP_WORD wLastInFragNum; /*2 - 76 LAST_IN_FRAG_NUM */
66  APP_WORD wInSerialNum; /*2 - 78 IN_SERIAL_NUM */
67  APP_WORD wReplyCount; /*2 - 80 REPLY_COUNT */
68  APP_WORD wInLen; /*2 - 82 DATA LEN */
69  APP_WORD wOutLen; /*2 - 84 */
70  APP_BYTE byLittleEndian; /*1 - 85 */
71 }PACK_ALIGNEMENT(ST_CL_SERVER_MACHINE_RT),APP_FAR *LPST_CL_SERVER_MACHINE_RT;
72 
73 
74 
75 typedef struct _CL_SERVER_MACHINE_SND
76 {
77  ST_CLR_RPC_UUID uuidActivityId; /*ACTIVITY_ID */
78  ST_CLR_RPC_UUID uuidObjId; /*OBJ_ID */
79  ST_CLR_RPC_UUID uuidIfId; /*IF_ID */
80  APP_DWORD dwIfVersion; /*IF_VERSION */
81  APP_DWORD dwSeqNum; /*SEQ_NUM */
82  APP_DWORD dwBootTime; /*BOOT_TIME */
83  APP_DWORD dwFaultStatus; /*FAULT_STATUS */
84  APP_DWORD dwRejectStatus; /*REJECT_STATUS */
85  APP_LPBYTE pbyOutParams; /*OUT_PARAMS */
86  APP_WORD wOpNum; /*OP_NUM */
87  APP_WORD wFragNum; /*FRAG_NUM */
88  APP_WORD wSerialNum; /*SERIAL_NUM */
89  APP_WORD wLen;
90  APP_BYTE byReplyType; /*REPLY_TYPE */
91  ST_OS_SOCKADDR_IN stSockAdr;
92 }PACK_ALIGNEMENT(ST_CL_SERVER_MACHINE_SND),APP_FAR* LPST_CL_SERVER_MACHINE_SND;
93 
94 /*---------------------------------------------------------------------------*/
95 /* CONDITION */
96 /*---------------------------------------------------------------------------*/
97 
99 {
100  APP_DWORD bBroadcast;
101  APP_DWORD bBurst;
102  APP_DWORD bContextRequest;
103  APP_DWORD bIdempotent;
104  APP_DWORD bLastInFrag;
105  APP_DWORD bLastOutFrag;
106  APP_DWORD bMaybe;
107  APP_DWORD bReturnPendingCancel;
108  APP_DWORD bSndFrag;
109  APP_DWORD bSndLastFrag;
110  APP_DWORD bSndPendingCancel;
111 }PACK_ALIGNEMENT(ST_CL_SERVER_COND),*PST_CL_SERVER_COND;
112 
113 /*Set Condition*/
114 #define TR_COND_BROADCAST(machine) ((machine)->stCondition.bBroadcast=1)
115 #define TR_COND_BURST(machine) ((machine)->stCondition.bBurst=1)
116 #define TR_COND_CONTEXT_REQUEST(machine) ((machine)->stCondition.bContextRequest=1)
117 #define TR_COND_IDEMPOTENT(machine) ((machine)->stCondition.bIdempotent=1)
118 #define TR_COND_LAST_IN_FRAG(machine) ((machine)->stCondition.bLastInFrag=1)
119 #define TR_COND_LAST_OUT_FRAG(machine) ((machine)->stCondition.bLastOutFrag=1)
120 #define TR_COND_MAYBE(machine) ((machine)->stCondition.bMaybe=1)
121 #define TR_COND_RETURN_PENDING_CANCEL(machine) ((machine)->stCondition.bReturnPendingCancel=1)
122 #define TR_COND_SND_FRAG(machine) ((machine)->stCondition.bSndFrag=1)
123 #define TR_COND_SND_LAST_FRAG(machine) ((machine)->stCondition.bSndLastFrag=1)
124 #define TR_COND_SND_PENDING_CANCEL(machine) ((machine)->stCondition.bSndPendingCancel=1)
125 
126 
127 /*Reset condition*/
128 #define FS_COND_BROADCAST(machine) ((machine)->stCondition.bBroadcast=0)
129 #define FS_COND_BURST(machine) ((machine)->stCondition.bBurst=0)
130 #define FS_COND_CONTEXT_REQUEST(machine) ((machine)->stCondition.bContextRequest=0)
131 #define FS_COND_IDEMPOTENT(machine) ((machine)->stCondition.bIdempotent=0)
132 #define FS_COND_LAST_IN_FRAG(machine) ((machine)->stCondition.bLastInFrag=0)
133 #define FS_COND_LAST_OUT_FRAG(machine) ((machine)->stCondition.bLastOutFrag=0)
134 #define FS_COND_MAYBE(machine) ((machine)->stCondition.bMaybe=0)
135 #define FS_COND_NO_FACK(machine) ((machine)->stCondition.bNoFack=0)
136 #define FS_COND_RETURN_PENDING_CANCEL(machine) ((machine)->stCondition.bReturnPendingCancel=0)
137 #define FS_COND_SND_FRAG(machine) ((machine)->stCondition.bSndFrag=0)
138 #define FS_COND_SND_LAST_FRAG(machine) ((machine)->stCondition.bSndLastFrag=0)
139 #define FS_COND_SND_PENDING_CANCEL(machine) ((machine)->stCondition.bSndPendingCancel=0)
140 
141 
142 /*Test simple condition*/
143 #define COND_BROADCAST(machine) ((machine)->stCondition.bBroadcast)
144 #define COND_BURST(machine) ((machine)->stCondition.bBurst)
145 #define COND_CONTEXT_REQUEST(machine) ((machine)->stCondition.bContextRequest)
146 #define COND_IDEMPOTENT(machine) ((machine)->stCondition.bIdempotent)
147 #define COND_LAST_IN_FRAG(machine) ((machine)->stCondition.bLastInFrag)
148 #define COND_LAST_OUT_FRAG(machine) ((machine)->stCondition.bLastOutFrag)
149 #define COND_MAYBE(machine) ((machine)->stCondition.bMaybe)
150 #define COND_RETURN_PENDING_CANCEL(machine) ((machine)->stCondition.bReturnPendingCancel)
151 #define COND_SND_FRAG(machine) ((machine)->stCondition.bSndFrag)
152 #define COND_SND_LAST_FRAG(machine) ((machine)->stCondition.bSndLastFrag)
153 #define COND_SND_PENDING_CANCEL(machine) ((machine)->stCondition.bSndPendingCancel)
154 
155 
156 /*COND_NON_IDEMPOTENT Statechart internal flag: non-idempotent (at-most-once) call.not COND_IDEMPOTENT and not COND_BROADCAST and not COND_MAYBE*/
157 #define COND_NON_IDEMPOTENT(machine)\
158  (!COND_IDEMPOTENT(machine) && !COND_BROADCAST(machine) && !COND_MAYBE(machine))
159 
160 /*COND_OUT_FRAG_NUM_EQ Statechart internal flag: received fragment number at client and last sent fragment number are equal. SND->FRAG_NUM=PDU->FRAG_NUM*/
161 #define COND_OUT_FRAG_NUM_EQ(machine)\
162  ((machine)->stSND.wFragNum == gstServerGlobal.stPDU.wFragNum)
163 
164 /*COND_OUT_FRAG_NUM_NE Statechart internal flag: received fragment number at client and last sent fragment number are not equal SND->FRAG_NUM/=PDU->FRAG_NUM*/
165 #define COND_OUT_FRAG_NUM_NE(machine)\
166  ((machine)->stSND.wFragNum != gstServerGlobal.stPDUwFragNum)
167 
168 /*COND_SEQ_NUM_EQ Statechart internal flag: received sequence number equals cached sequence number.PDU->SEQ_NUM=RT->SEQ_NUM*/
169 #define COND_SEQ_NUM_EQ(machine)\
170  (lpstServerGlobal->stPDU.dwSeqNum == (machine)->stRT.dwSeqNum)
171 
172 /*COND_SEQ_NUM_GT Statechart internal flag: received sequence number > cached sequence number.PDU->SEQ_NUM>RT->SEQ_NUM*/
173 #define COND_SEQ_NUM_GT(machine)\
174  ((long)lpstServerGlobal->stPDU.dwSeqNum > (long)(machine)->stRT.dwSeqNum)
175 
176 /*COND_SEQ_NUM_LE Statechart internal flag: received sequence number <= cached sequence number.PDU->SEQ_NUM<=RT->SEQ_NUM*/
177 #define COND_SEQ_NUM_LE(machine)\
178  (lpstServerGlobal->stPDU.dwSeqNum <= (machine)->stRT.dwSeqNum)
179 
180 /*COND_SEQ_NUM_LOST Statechart internal flag: cached sequence number invalid.RT->SEQ_NUM=0*/
181 #define COND_SEQ_NUM_LOST(machine)\
182  ((machine)->stRT.dwSeqNum ==0)
183 
184 /*---------------------------------------------------------------------------*/
185 /* SERVER STATE MACHINE CONTEXT */
186 /*---------------------------------------------------------------------------*/
187 typedef enum _enClServer{
188  enClServerNone =0,/*shall be the first, never change it*/
189  enClServerRun =1
190 } EN_CLSERVER_STATE;
191 
192 typedef enum _enSrvWorking{
193  enSrvWorkingNone =0,/*shall be the first, never change it*/
194  enSrvWorkingInit =1,
195  enSrvWorkingCall =2
196 } EN_SRV_WORKING;
197 
198 typedef enum _enSrvData{
199  enSrvDataNone =0,/*shall be the first, never change it*/
200  enSrvDataIndication =1,
201  enSrvDataProcessReq =2,
202  enSrvDataReplied =3,
203  enSrvDataReplying =4
204 } EN_SRV_DATA;
205 
206 
207 typedef struct _CL_SERVER_MACHINE
208 {
209  ST_RPC_REQ stRPCReq; /* current rpc request (external exchange) */
210  ST_CL_SERVER_COND stCondition; /* Current Condition of the state machine */
211  ST_CL_SERVER_MACHINE_RT stRT; /* runtime variable of the state machine */
212  ST_CL_SERVER_MACHINE_SND stSND; /* information on next packet to send */
213  ST_CLR_RPC_UUID uuidSession; /* UUID of current session */
214  LPST_CBF cbTimer[NB_SERVER_TIMER]; /* Timer Managment */
215 
216  EN_CLSERVER_STATE enClServerState;
217  EN_SRV_WORKING enClServerWorkingState;
218  EN_SRV_DATA enClServerDataState;
219 
220  APP_LPVOID lpstServerGlobal; /* To be able to find out all my father paramters */
221 
222 } PACK_ALIGNEMENT(ST_CL_SERVER),APP_FAR *LPST_CL_SERVER;
223 
224 #define GET_SRV_RPC_REQ(machine) ((machine).stRPCReq)
225 
226 
227 /*---------------------------------------------------------------------------*/
228 /* GLOBAL */
229 /*---------------------------------------------------------------------------*/
230 typedef struct _CL_SERVER_PDU_COND
231 {
232  APP_DWORD bBroadcast;
233  APP_DWORD bIdempotent;
234  APP_DWORD bMaybe;
235  APP_DWORD bNoFack;
236  APP_DWORD bFrag;
237  APP_DWORD bLastFrag;
238 }PACK_ALIGNEMENT(ST_CL_COND_PDU),APP_FAR* LPST_CL_COND_PDU;
239 
240 typedef struct _CL_SERVER_PDU
241 {
242  ST_CLR_RPC_UUID uuidActivityId; /*ACTIVITY_ID */
243  ST_CLR_RPC_UUID uuidObjId; /*OBJ_ID */
244  ST_CLR_RPC_UUID uuidIfId; /*IF_ID */
245  APP_DWORD dwIfVersion; /*IF_VERSION */
246  APP_DWORD dwSeqNum; /*SEQ_NUM */
247  APP_DWORD dwBootTime; /*BOOT_TIME */
248  APP_DWORD dwCancelVers; /*CANCEL_VERS */
249  APP_DWORD dwCancelID; /*CANCEL_ID */
250  APP_LPBYTE pbyBody; /*BODY */
251  APP_WORD wOpNum; /*OP_NUM */
252  APP_WORD wFragNum; /*FRAG_NUM */
253  APP_WORD wSerialNum; /*SERIAL_NUM */
254  APP_WORD wLen; /*DATA LEN */
255  APP_BYTE byRequestType; /*TYPE */
256  APP_BYTE byLittleEndian;
257 }PACK_ALIGNEMENT(ST_CL_SERVER_PDU),APP_FAR* LPST_CL_SERVER_PDU;
258 
259 typedef struct _CL_SERVER_GLOBAL
260 {
261  /*All instance of server machine */
262  ST_CL_SERVER stClServer[MAX_RPCSERVER];
263  ST_OS_SOCKADDR_IN stSockAdr; /* Client IP/Port */
264  /*Indirection Interface -> Fonction in stub to call */
265  ST_INTERFACE_REGISTER stResiteredInterface[MAX_REG_INTERFACE];
266  ST_CL_SERVER_PDU stPDU; /* Last pdu received */
267  ST_CL_COND_PDU stCondition; /* PDU flag */
268 
269  APP_DWORD dwSysBootTime; /* Start Time */
270  APP_DWORD dwSocket; /* Socket Rec */
271 
272  APP_DWORD dwIPAddressLastCaller; /* Last caller ip address */
273 
274 
275  LPST_RPC_CONF lpRPCParam;
276 
277 
278 }PACK_ALIGNEMENT(ST_CL_SERVER_GLOBAL),APP_FAR* LPST_CL_SERVER_GLOBAL;
279 
280 extern ST_CL_SERVER_GLOBAL gstServerGlobal[MAX_DEVICE];
281 
282 
283 typedef struct _ST_EPM {
284  APP_WORD wEPMState;
285 }PACK_ALIGNEMENT(ST_EPM), APP_FAR * LPST_EPM;
286 
287 
288 #define GET_EPM_STATE(a) a.wEPMState
289 #define SET_EPM_STATE(a,b) a.wEPMState =b
290 
291 #define GET_EPM_RPC_CALL(a) a.stRPCCall
292 
293 typedef struct _EPT_ENTRY_T {
294  APP_BYTE handle[20];
295  APP_DWORD num_ents;
296  APP_DWORD max_count;
297  APP_DWORD offset;
298  APP_DWORD actual;
299  ST_CLR_RPC_UUID uuidObject;
300  APP_DWORD referenceid;
301  APP_DWORD annotation_offset;
302  APP_DWORD annotation_length;
303  APP_BYTE annotation[64];
304  APP_DWORD length1;
305  APP_DWORD length2;
306  APP_WORD nbfloors;
307 }PACK_ALIGNEMENT(EPT_ENTRY_T), APP_FAR * LPEPT_ENTRY_T;
308 
309 typedef struct _FLOOR_DOD_T {
310  APP_WORD wLHS_Len;
311  APP_BYTE byProtocol;
312 }PACK_ALIGNEMENT(FLOOR_DOD_T), APP_FAR * LPFLOOR_DOD_T;
313 
314 
315 #define FS_COND_PDU_BROADCAST (lpstServerGlobal->stCondition.bBroadcast = 0)
316 #define FS_COND_PDU_IDEMPOTENT (lpstServerGlobal->stCondition.bIdempotent = 0)
317 #define FS_COND_PDU_MAYBE (lpstServerGlobal->stCondition.bMaybe = 0)
318 #define FS_COND_PDU_NOFACK (lpstServerGlobal->stCondition.bNoFack = 0)
319 #define FS_COND_PDU_FRAG (lpstServerGlobal->stCondition.bFrag = 0)
320 #define FS_COND_PDU_LASTFRAG (lpstServerGlobal->stCondition.bLastFrag = 0)
321 
322 #define TR_COND_PDU_BROADCAST (lpstServerGlobal->stCondition.bBroadcast = 1)
323 #define TR_COND_PDU_IDEMPOTENT (lpstServerGlobal->stCondition.bIdempotent = 1)
324 #define TR_COND_PDU_MAYBE (lpstServerGlobal->stCondition.bMaybe = 1)
325 #define TR_COND_PDU_NOFACK (lpstServerGlobal->stCondition.bNoFack = 1)
326 #define TR_COND_PDU_FRAG (lpstServerGlobal->stCondition.bFrag = 1)
327 #define TR_COND_PDU_LASTFRAG (lpstServerGlobal->stCondition.bLastFrag = 1)
328 
329 #define COND_PDU_BROADCAST (lpstServerGlobal->stCondition.bBroadcast )
330 #define COND_PDU_IDEMPOTENT (lpstServerGlobal->stCondition.bIdempotent)
331 #define COND_PDU_MAYBE (lpstServerGlobal->stCondition.bMaybe )
332 #define COND_PDU_NOFACK (lpstServerGlobal->stCondition.bNoFack )
333 #define COND_PDU_FRAG (lpstServerGlobal->stCondition.bFrag )
334 #define COND_PDU_LASTFRAG (lpstServerGlobal->stCondition.bLastFrag )
335 
336 
337 #define EPM_EVENT_NONE 0xFFFF
338 #define EPM_EVENT_LOOKUP 0
339 #define EPM_EVENT_LOOKUPFREE 1
340 #define MAX_EPM_EVENT EPM_EVENT_LOOKUPFREE
341 
342 
343 #define EPM_W_L_UP 0
344 #define EPM_WHO 1
345 #define EPM_R_L_UP 2
346 #define EPM_REJECT 3
347 #define EPM_W_L_UP_FREE 4
348 
349 
350 
351 /*---------------------------------------------------------------------------*/
352 /* EVENT STATE */
353 /*---------------------------------------------------------------------------*/
354 APP_VOID clserver_event_abort(LPST_CL_SERVER pstClServer);
355 
356 APP_VOID clserver_event_processing_fault(LPST_CL_SERVER pstClServer);
357 APP_VOID clserver_event_processing_fdne (LPST_CL_SERVER pstClServer);
358 APP_VOID clserver_event_proc_response (LPST_CL_SERVER pstClServer);
359 APP_BOOL clserver_event_receive_pdu (LPST_CL_SERVER pstClServer);
360 
361 APP_VOID clserver_event_tmidle (LPST_CL_SERVER pstClServer);
362 APP_VOID clserver_event_tmresend(LPST_CL_SERVER pstClServer);
363 
364 /*---------------------------------------------------------------------------*/
365 /* ACTION */
366 /*---------------------------------------------------------------------------*/
367 APP_VOID clserver_action_enter_server (LPST_CL_SERVER pstClServer);
368 APP_VOID clserver_action_fack_nocall_call(LPST_CL_SERVER pstClServer,APP_BYTE byReplyType);
369 APP_VOID clserver_action_resend_out_frags(LPST_CL_SERVER pstClServer);
370 
371 APP_VOID clserver_action_server_reject(APP_DWORD dwError, LPST_CL_SERVER_GLOBAL lpstServerGlobal);
372 APP_VOID clserver_action_server_nocall( LPST_CL_SERVER_GLOBAL lpstServerGlobal);
373 /*---------------------------------------------------------------------------*/
374 /* ACTIVITY */
375 /*---------------------------------------------------------------------------*/
376 APP_VOID clserver_cancel_req (LPST_CL_SERVER pstClServer);
377 APP_VOID clserver_cancel_res (LPST_CL_SERVER pstClServer);
378 APP_VOID clserver_AbortCall (LPST_CL_SERVER pstClServer);
379 APP_VOID clserver_SendPkt (LPST_CL_SERVER pstClServer);
380 
381 APP_VOID clserver_StubCall(LPST_CL_SERVER pstClServer, LPST_CL_SERVER_GLOBAL lpstServerGlobal);
382 
383 APP_VOID clserver_StartTimer(LPST_CL_SERVER pstClServer,APP_BYTE byIdTimer);
384 APP_VOID clserver_StopTimer (LPST_CL_SERVER pstClServer,APP_BYTE byIdTimer);
385 /*---------------------------------------------------------------------------*/
386 /* STATE MACHINE MANAGMENT (EXTERNAL INTERFACE) */
387 /*---------------------------------------------------------------------------*/
388 APP_VOID clserver_InitStateMachine(LPST_CL_SERVER_GLOBAL lpstServerGlobal);
389 APP_BOOL clserver_Step (LPST_CL_SERVER_GLOBAL lpstServerGlobal);
390 APP_VOID clserver_ExitStateMachine(LPST_CL_SERVER_GLOBAL lpstServerGlobal);
391 
392 APP_VOID clserver_RegisterInterface(LPST_INTERFACE_REGISTER pstRegInt);
393 
394 #include "os_unpck.h"
395 
396 #ifdef __TEST_SIMU_ERROR__
397  /*Only used for unitary test of this module this function shall be implemented in test module*/
398  /*Return APP_TRUE : This packet shall not be send to simulate a lost packet*/
399  APP_BOOL test_rpcserver_lost_packet(APP_DWORD dwPacket);
400  APP_BOOL test_rpcserver_do_not_rec_packet(APP_DWORD dwPacket);
401 #endif
402 
403 #endif/*__RPC_CLSERVER_H__*/
Definition: clserver.h:75
Definition: clserver.h:48
Definition: clserver.h:98
Definition: stk_sckt.h:49
Definition: clserver.h:240
Definition: clserver.h:283
Definition: clserver.h:207
Definition: clserver.h:309
Definition: config.h:59
Definition: schedule.h:40
Definition: clserver.h:259
Definition: clserver.h:230
Definition: clserver.h:293