blob: c27ca8f8c2f3fb5c23526cbead0d94e93db778d5 [file] [log] [blame]
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001/****************************************************************************
2
3 (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4 www.systec-electronic.com
5
6 Project: openPOWERLINK
7
8 Description: source file for NMT-CN-Userspace-Module
9
10 License:
11
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
14 are met:
15
16 1. Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18
19 2. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
22
23 3. Neither the name of SYSTEC electronic GmbH nor the names of its
24 contributors may be used to endorse or promote products derived
25 from this software without prior written permission. For written
26 permission, please contact info@systec-electronic.com.
27
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32 COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 POSSIBILITY OF SUCH DAMAGE.
40
41 Severability Clause:
42
43 If a provision of this License is or becomes illegal, invalid or
44 unenforceable in any jurisdiction, that shall not affect:
45 1. the validity or enforceability in that jurisdiction of any other
46 provision of this License; or
47 2. the validity or enforceability in other jurisdictions of that or
48 any other provision of this License.
49
50 -------------------------------------------------------------------------
51
52 $RCSfile: EplNmtCnu.c,v $
53
54 $Author: D.Krueger $
55
56 $Revision: 1.6 $ $Date: 2008/10/17 15:32:32 $
57
58 $State: Exp $
59
60 Build Environment:
61 GCC V3.4
62
63 -------------------------------------------------------------------------
64
65 Revision History:
66
67 2006/06/09 k.t.: start of the implementation
68
69****************************************************************************/
70
71#include "EplInc.h"
72#include "user/EplNmtCnu.h"
73#include "user/EplDlluCal.h"
74
75#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_CN)) != 0)
76
77/***************************************************************************/
78/* */
79/* */
80/* G L O B A L D E F I N I T I O N S */
81/* */
82/* */
83/***************************************************************************/
84
85//---------------------------------------------------------------------------
86// const defines
87//---------------------------------------------------------------------------
88
89//---------------------------------------------------------------------------
90// local types
91//---------------------------------------------------------------------------
92
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -080093typedef struct {
94 unsigned int m_uiNodeId;
95 tEplNmtuCheckEventCallback m_pfnCheckEventCb;
Daniel Krueger9d7164c2008-12-19 11:41:57 -080096
97} tEplNmtCnuInstance;
98
99//---------------------------------------------------------------------------
100// modul globale vars
101//---------------------------------------------------------------------------
102
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800103static tEplNmtCnuInstance EplNmtCnuInstance_g;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800104
105//---------------------------------------------------------------------------
106// local function prototypes
107//---------------------------------------------------------------------------
108
109static tEplNmtCommand EplNmtCnuGetNmtCommand(tEplFrameInfo * pFrameInfo_p);
110
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700111static BOOL EplNmtCnuNodeIdList(u8 * pbNmtCommandDate_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800112
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700113static tEplKernel EplNmtCnuCommandCb(tEplFrameInfo *pFrameInfo_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800114
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800115//=========================================================================//
116// //
117// P U B L I C F U N C T I O N S //
118// //
119//=========================================================================//
120
121//---------------------------------------------------------------------------
122//
123// Function: EplNmtCnuInit
124//
125// Description: init the first instance of the module
126//
127//
128//
129// Parameters: uiNodeId_p = NodeId of the local node
130//
131//
132// Returns: tEplKernel = errorcode
133//
134//
135// State:
136//
137//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700138tEplKernel EplNmtCnuInit(unsigned int uiNodeId_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800139{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800140 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800141
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800142 Ret = EplNmtCnuAddInstance(uiNodeId_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800143
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800144 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800145}
146
147//---------------------------------------------------------------------------
148//
149// Function: EplNmtCnuAddInstance
150//
151// Description: init the add new instance of the module
152//
153//
154//
155// Parameters: uiNodeId_p = NodeId of the local node
156//
157//
158// Returns: tEplKernel = errorcode
159//
160//
161// State:
162//
163//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700164tEplKernel EplNmtCnuAddInstance(unsigned int uiNodeId_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800165{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800166 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800167
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800168 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800169
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800170 // reset instance structure
171 EPL_MEMSET(&EplNmtCnuInstance_g, 0, sizeof(EplNmtCnuInstance_g));
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800172
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800173 // save nodeid
174 EplNmtCnuInstance_g.m_uiNodeId = uiNodeId_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800175
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800176 // register callback-function for NMT-commands
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800177#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800178 Ret = EplDlluCalRegAsndService(kEplDllAsndNmtCommand,
179 EplNmtCnuCommandCb,
180 kEplDllAsndFilterLocal);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800181#endif
182
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800183 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800184
185}
186
187//---------------------------------------------------------------------------
188//
189// Function: EplNmtCnuDelInstance
190//
191// Description: delte instance of the module
192//
193//
194//
195// Parameters:
196//
197//
198// Returns: tEplKernel = errorcode
199//
200//
201// State:
202//
203//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700204tEplKernel EplNmtCnuDelInstance(void)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800205{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800206 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800207
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800208 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800209
210#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800211 // deregister callback function from DLL
212 Ret = EplDlluCalRegAsndService(kEplDllAsndNmtCommand,
213 NULL, kEplDllAsndFilterNone);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800214#endif
215
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800216 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800217}
218
219//---------------------------------------------------------------------------
220//
221// Function: EplNmtCnuSendNmtRequest
222//
223// Description: Send an NMT-Request to the MN
224//
225//
226//
227// Parameters: uiNodeId_p = NodeId of the local node
228// NmtCommand_p = requested NMT-Command
229//
230//
231// Returns: tEplKernel = errorcode
232//
233//
234// State:
235//
236//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700237tEplKernel EplNmtCnuSendNmtRequest(unsigned int uiNodeId_p,
238 tEplNmtCommand NmtCommand_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800239{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800240 tEplKernel Ret;
241 tEplFrameInfo NmtRequestFrameInfo;
242 tEplFrame NmtRequestFrame;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800243
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800244 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800245
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800246 // build frame
247 EPL_MEMSET(&NmtRequestFrame.m_be_abDstMac[0], 0x00, sizeof(NmtRequestFrame.m_be_abDstMac)); // set by DLL
248 EPL_MEMSET(&NmtRequestFrame.m_be_abSrcMac[0], 0x00, sizeof(NmtRequestFrame.m_be_abSrcMac)); // set by DLL
249 AmiSetWordToBe(&NmtRequestFrame.m_be_wEtherType,
250 EPL_C_DLL_ETHERTYPE_EPL);
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700251 AmiSetByteToLe(&NmtRequestFrame.m_le_bDstNodeId, (u8) EPL_C_ADR_MN_DEF_NODE_ID); // node id of the MN
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800252 AmiSetByteToLe(&NmtRequestFrame.m_le_bMessageType,
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700253 (u8) kEplMsgTypeAsnd);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800254 AmiSetByteToLe(&NmtRequestFrame.m_Data.m_Asnd.m_le_bServiceId,
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700255 (u8) kEplDllAsndNmtRequest);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800256 AmiSetByteToLe(&NmtRequestFrame.m_Data.m_Asnd.m_Payload.
257 m_NmtRequestService.m_le_bNmtCommandId,
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700258 (u8) NmtCommand_p);
259 AmiSetByteToLe(&NmtRequestFrame.m_Data.m_Asnd.m_Payload.m_NmtRequestService.m_le_bTargetNodeId, (u8) uiNodeId_p); // target for the nmt command
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800260 EPL_MEMSET(&NmtRequestFrame.m_Data.m_Asnd.m_Payload.m_NmtRequestService.
261 m_le_abNmtCommandData[0], 0x00,
262 sizeof(NmtRequestFrame.m_Data.m_Asnd.m_Payload.
263 m_NmtRequestService.m_le_abNmtCommandData));
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800264
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800265 // build info-structure
266 NmtRequestFrameInfo.m_NetTime.m_dwNanoSec = 0;
267 NmtRequestFrameInfo.m_NetTime.m_dwSec = 0;
268 NmtRequestFrameInfo.m_pFrame = &NmtRequestFrame;
269 NmtRequestFrameInfo.m_uiFrameSize = EPL_C_DLL_MINSIZE_NMTREQ; // sizeof(NmtRequestFrame);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800270
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800271 // send NMT-Request
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800272#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800273 Ret = EplDlluCalAsyncSend(&NmtRequestFrameInfo, // pointer to frameinfo
274 kEplDllAsyncReqPrioNmt); // priority
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800275#endif
276
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800277 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800278}
279
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800280//---------------------------------------------------------------------------
281//
282// Function: EplNmtCnuRegisterStateChangeCb
283//
284// Description: register Callback-function go get informed about a
285// NMT-Change-State-Event
286//
287//
288//
289// Parameters: pfnEplNmtStateChangeCb_p = functionpointer
290//
291//
292// Returns: tEplKernel = errorcode
293//
294//
295// State:
296//
297//---------------------------------------------------------------------------
298
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700299tEplKernel EplNmtCnuRegisterCheckEventCb(tEplNmtuCheckEventCallback pfnEplNmtCheckEventCb_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800300{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800301 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800302
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800303 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800304
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800305 // save callback-function in modul global var
306 EplNmtCnuInstance_g.m_pfnCheckEventCb = pfnEplNmtCheckEventCb_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800307
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800308 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800309
310}
311
312//=========================================================================//
313// //
314// P R I V A T E F U N C T I O N S //
315// //
316//=========================================================================//
317
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800318//---------------------------------------------------------------------------
319//
320// Function: EplNmtCnuCommandCb
321//
322// Description: callback funktion for NMT-Commands
323//
324//
325//
326// Parameters: pFrameInfo_p = Frame with the NMT-Commando
327//
328//
329// Returns: tEplKernel = errorcode
330//
331//
332// State:
333//
334//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700335static tEplKernel EplNmtCnuCommandCb(tEplFrameInfo *pFrameInfo_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800336{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800337 tEplKernel Ret = kEplSuccessful;
338 tEplNmtCommand NmtCommand;
339 BOOL fNodeIdInList;
340 tEplNmtEvent NmtEvent = kEplNmtEventNoEvent;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800341
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800342 if (pFrameInfo_p == NULL) {
343 Ret = kEplNmtInvalidFramePointer;
344 goto Exit;
345 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800346
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800347 NmtCommand = EplNmtCnuGetNmtCommand(pFrameInfo_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800348
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800349 // check NMT-Command
350 switch (NmtCommand) {
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800351
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800352 //------------------------------------------------------------------------
353 // plain NMT state commands
354 case kEplNmtCmdStartNode:
355 { // send NMT-Event to state maschine kEplNmtEventStartNode
356 NmtEvent = kEplNmtEventStartNode;
357 break;
358 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800359
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800360 case kEplNmtCmdStopNode:
361 { // send NMT-Event to state maschine kEplNmtEventStopNode
362 NmtEvent = kEplNmtEventStopNode;
363 break;
364 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800365
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800366 case kEplNmtCmdEnterPreOperational2:
367 { // send NMT-Event to state maschine kEplNmtEventEnterPreOperational2
368 NmtEvent = kEplNmtEventEnterPreOperational2;
369 break;
370 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800371
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800372 case kEplNmtCmdEnableReadyToOperate:
373 { // send NMT-Event to state maschine kEplNmtEventEnableReadyToOperate
374 NmtEvent = kEplNmtEventEnableReadyToOperate;
375 break;
376 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800377
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800378 case kEplNmtCmdResetNode:
379 { // send NMT-Event to state maschine kEplNmtEventResetNode
380 NmtEvent = kEplNmtEventResetNode;
381 break;
382 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800383
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800384 case kEplNmtCmdResetCommunication:
385 { // send NMT-Event to state maschine kEplNmtEventResetCom
386 NmtEvent = kEplNmtEventResetCom;
387 break;
388 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800389
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800390 case kEplNmtCmdResetConfiguration:
391 { // send NMT-Event to state maschine kEplNmtEventResetConfig
392 NmtEvent = kEplNmtEventResetConfig;
393 break;
394 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800395
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800396 case kEplNmtCmdSwReset:
397 { // send NMT-Event to state maschine kEplNmtEventSwReset
398 NmtEvent = kEplNmtEventSwReset;
399 break;
400 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800401
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800402 //------------------------------------------------------------------------
403 // extended NMT state commands
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800404
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800405 case kEplNmtCmdStartNodeEx:
406 {
407 // check if own nodeid is in EPL node list
408 fNodeIdInList =
409 EplNmtCnuNodeIdList(&
410 (pFrameInfo_p->m_pFrame->m_Data.
411 m_Asnd.m_Payload.
412 m_NmtCommandService.
413 m_le_abNmtCommandData[0]));
414 if (fNodeIdInList != FALSE) { // own nodeid in list
415 // send event to process command
416 NmtEvent = kEplNmtEventStartNode;
417 }
418 break;
419 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800420
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800421 case kEplNmtCmdStopNodeEx:
422 { // check if own nodeid is in EPL node list
423 fNodeIdInList =
424 EplNmtCnuNodeIdList(&pFrameInfo_p->m_pFrame->m_Data.
425 m_Asnd.m_Payload.
426 m_NmtCommandService.
427 m_le_abNmtCommandData[0]);
428 if (fNodeIdInList != FALSE) { // own nodeid in list
429 // send event to process command
430 NmtEvent = kEplNmtEventStopNode;
431 }
432 break;
433 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800434
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800435 case kEplNmtCmdEnterPreOperational2Ex:
436 { // check if own nodeid is in EPL node list
437 fNodeIdInList =
438 EplNmtCnuNodeIdList(&pFrameInfo_p->m_pFrame->m_Data.
439 m_Asnd.m_Payload.
440 m_NmtCommandService.
441 m_le_abNmtCommandData[0]);
442 if (fNodeIdInList != FALSE) { // own nodeid in list
443 // send event to process command
444 NmtEvent = kEplNmtEventEnterPreOperational2;
445 }
446 break;
447 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800448
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800449 case kEplNmtCmdEnableReadyToOperateEx:
450 { // check if own nodeid is in EPL node list
451 fNodeIdInList =
452 EplNmtCnuNodeIdList(&pFrameInfo_p->m_pFrame->m_Data.
453 m_Asnd.m_Payload.
454 m_NmtCommandService.
455 m_le_abNmtCommandData[0]);
456 if (fNodeIdInList != FALSE) { // own nodeid in list
457 // send event to process command
458 NmtEvent = kEplNmtEventEnableReadyToOperate;
459 }
460 break;
461 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800462
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800463 case kEplNmtCmdResetNodeEx:
464 { // check if own nodeid is in EPL node list
465 fNodeIdInList =
466 EplNmtCnuNodeIdList(&pFrameInfo_p->m_pFrame->m_Data.
467 m_Asnd.m_Payload.
468 m_NmtCommandService.
469 m_le_abNmtCommandData[0]);
470 if (fNodeIdInList != FALSE) { // own nodeid in list
471 // send event to process command
472 NmtEvent = kEplNmtEventResetNode;
473 }
474 break;
475 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800476
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800477 case kEplNmtCmdResetCommunicationEx:
478 { // check if own nodeid is in EPL node list
479 fNodeIdInList =
480 EplNmtCnuNodeIdList(&pFrameInfo_p->m_pFrame->m_Data.
481 m_Asnd.m_Payload.
482 m_NmtCommandService.
483 m_le_abNmtCommandData[0]);
484 if (fNodeIdInList != FALSE) { // own nodeid in list
485 // send event to process command
486 NmtEvent = kEplNmtEventResetCom;
487 }
488 break;
489 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800490
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800491 case kEplNmtCmdResetConfigurationEx:
492 { // check if own nodeid is in EPL node list
493 fNodeIdInList =
494 EplNmtCnuNodeIdList(&pFrameInfo_p->m_pFrame->m_Data.
495 m_Asnd.m_Payload.
496 m_NmtCommandService.
497 m_le_abNmtCommandData[0]);
498 if (fNodeIdInList != FALSE) { // own nodeid in list
499 // send event to process command
500 NmtEvent = kEplNmtEventResetConfig;
501 }
502 break;
503 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800504
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800505 case kEplNmtCmdSwResetEx:
506 { // check if own nodeid is in EPL node list
507 fNodeIdInList =
508 EplNmtCnuNodeIdList(&pFrameInfo_p->m_pFrame->m_Data.
509 m_Asnd.m_Payload.
510 m_NmtCommandService.
511 m_le_abNmtCommandData[0]);
512 if (fNodeIdInList != FALSE) { // own nodeid in list
513 // send event to process command
514 NmtEvent = kEplNmtEventSwReset;
515 }
516 break;
517 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800518
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800519 //------------------------------------------------------------------------
520 // NMT managing commands
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800521
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800522 // TODO: add functions to process managing command (optional)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800523
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800524 case kEplNmtCmdNetHostNameSet:
525 {
526 break;
527 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800528
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800529 case kEplNmtCmdFlushArpEntry:
530 {
531 break;
532 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800533
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800534 //------------------------------------------------------------------------
535 // NMT info services
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800536
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800537 // TODO: forward event with infos to the application (optional)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800538
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800539 case kEplNmtCmdPublishConfiguredCN:
540 {
541 break;
542 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800543
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800544 case kEplNmtCmdPublishActiveCN:
545 {
546 break;
547 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800548
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800549 case kEplNmtCmdPublishPreOperational1:
550 {
551 break;
552 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800553
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800554 case kEplNmtCmdPublishPreOperational2:
555 {
556 break;
557 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800558
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800559 case kEplNmtCmdPublishReadyToOperate:
560 {
561 break;
562 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800563
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800564 case kEplNmtCmdPublishOperational:
565 {
566 break;
567 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800568
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800569 case kEplNmtCmdPublishStopped:
570 {
571 break;
572 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800573
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800574 case kEplNmtCmdPublishEmergencyNew:
575 {
576 break;
577 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800578
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800579 case kEplNmtCmdPublishTime:
580 {
581 break;
582 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800583
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800584 //-----------------------------------------------------------------------
585 // error from MN
586 // -> requested command not supported by MN
587 case kEplNmtCmdInvalidService:
588 {
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800589
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800590 // TODO: errorevent to application
591 break;
592 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800593
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800594 //------------------------------------------------------------------------
595 // default
596 default:
597 {
598 Ret = kEplNmtUnknownCommand;
599 goto Exit;
600 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800601
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800602 } // end of switch(NmtCommand)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800603
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800604 if (NmtEvent != kEplNmtEventNoEvent) {
605 if (EplNmtCnuInstance_g.m_pfnCheckEventCb != NULL) {
606 Ret = EplNmtCnuInstance_g.m_pfnCheckEventCb(NmtEvent);
607 if (Ret == kEplReject) {
608 Ret = kEplSuccessful;
609 goto Exit;
610 } else if (Ret != kEplSuccessful) {
611 goto Exit;
612 }
613 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800614#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800615 Ret = EplNmtuNmtEvent(NmtEvent);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800616#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800617 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800618
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800619 Exit:
620 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800621
622}
623
624//---------------------------------------------------------------------------
625//
626// Function: EplNmtCnuGetNmtCommand()
627//
628// Description: returns the NMT-Command from the frame
629//
630//
631//
632// Parameters: pFrameInfo_p = pointer to the Frame
633// with the NMT-Command
634//
635//
636// Returns: tEplNmtCommand = NMT-Command
637//
638//
639// State:
640//
641//---------------------------------------------------------------------------
642static tEplNmtCommand EplNmtCnuGetNmtCommand(tEplFrameInfo * pFrameInfo_p)
643{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800644 tEplNmtCommand NmtCommand;
645 tEplNmtCommandService *pNmtCommandService;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800646
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800647 pNmtCommandService =
648 &pFrameInfo_p->m_pFrame->m_Data.m_Asnd.m_Payload.
649 m_NmtCommandService;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800650
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800651 NmtCommand =
652 (tEplNmtCommand) AmiGetByteFromLe(&pNmtCommandService->
653 m_le_bNmtCommandId);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800654
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800655 return NmtCommand;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800656}
657
658//---------------------------------------------------------------------------
659//
660// Function: EplNmtCnuNodeIdList()
661//
662// Description: check if the own nodeid is set in EPL Node List
663//
664//
665//
666// Parameters: pbNmtCommandDate_p = pointer to the data of the NMT Command
667//
668//
669// Returns: BOOL = TRUE if nodeid is set in EPL Node List
670// FALSE if nodeid not set in EPL Node List
671//
672//
673// State:
674//
675//---------------------------------------------------------------------------
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700676static BOOL EplNmtCnuNodeIdList(u8 * pbNmtCommandDate_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800677{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800678 BOOL fNodeIdInList;
679 unsigned int uiByteOffset;
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700680 u8 bBitOffset;
681 u8 bNodeListByte;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800682
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800683 // get byte-offset of the own nodeid in NodeIdList
684 // devide though 8
685 uiByteOffset = (unsigned int)(EplNmtCnuInstance_g.m_uiNodeId >> 3);
686 // get bitoffset
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700687 bBitOffset = (u8) EplNmtCnuInstance_g.m_uiNodeId % 8;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800688
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800689 bNodeListByte = AmiGetByteFromLe(&pbNmtCommandDate_p[uiByteOffset]);
690 if ((bNodeListByte & bBitOffset) == 0) {
691 fNodeIdInList = FALSE;
692 } else {
693 fNodeIdInList = TRUE;
694 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800695
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800696 return fNodeIdInList;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800697}
698
699#endif // #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_CN)) != 0)
700
701// EOF