|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * This file was autogenerated by rpcgen, but should be modified by the developer. |
|
16 * Make sure you don't use the -component_mod flag in future or this file will be overwritten. |
|
17 * Fri Oct 10 17:55:34 2003 |
|
18 * Switches Includes |
|
19 * System Includes |
|
20 * |
|
21 */ |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 #include <stdio.h> |
|
27 #include <signal.h> |
|
28 #ifndef WIN32 |
|
29 #include <sys/socket.h> |
|
30 #include <netinet/in.h> |
|
31 #include <arpa/inet.h> |
|
32 #include <net/if.h> |
|
33 #else |
|
34 #include <winsock2.h> |
|
35 #endif |
|
36 |
|
37 |
|
38 /**************************************************************************************** |
|
39 * |
|
40 * Local Includes |
|
41 * |
|
42 ***************************************************************************************/ |
|
43 #include "CSvcHacontroller.h" |
|
44 #include "CSHacontroller.h" |
|
45 #include "../IntegerAllocatorLibrary/CIntegerAllocator.h" |
|
46 |
|
47 |
|
48 /**************************************************************************************** |
|
49 * |
|
50 * Definition |
|
51 * |
|
52 ***************************************************************************************/ |
|
53 #define TEMPLATE_HA_CONFIG_FILE "dynhad.template.conf" |
|
54 #define MOBILE_AGENT_COMMAND_LINE "./dynhad --fg --debug --config " |
|
55 #define MAXCOMMANDLINELENGTH (31 + 256 + 1) |
|
56 #define MAXTUNNELS 32 |
|
57 #define MAXINTERFACECONFIGENTRY (IFNAMSIZ + 128) |
|
58 |
|
59 |
|
60 /**************************************************************************************** |
|
61 * |
|
62 * Macro Functions |
|
63 * |
|
64 ***************************************************************************************/ |
|
65 #ifdef WIN32 |
|
66 #define API_SUCCESS (0) |
|
67 #define dynamics_ha_init(a) (API_SUCCESS) |
|
68 #define dynamics_ha_get_status(a,b) (API_SUCCESS) |
|
69 #define dynamics_ha_get_tunnels(a,b,c) (API_SUCCESS) |
|
70 #define dynamics_ha_get_tunnel_info(a,b,c) (API_SUCCESS) |
|
71 #define dynamics_ha_destroy_tunnel(a,b) (API_SUCCESS) |
|
72 #define dynamics_ha_enable_mobile(a,b,c) (API_SUCCESS) |
|
73 #define dynamics_ha_get_care_of_addr(a,b,c) (API_SUCCESS) |
|
74 #endif |
|
75 |
|
76 |
|
77 /**************************************************************************************** |
|
78 * |
|
79 * Implementation |
|
80 * |
|
81 ***************************************************************************************/ |
|
82 CSHacontroller::CSHacontroller() |
|
83 { |
|
84 iDynamicsCallTimeout = -1; |
|
85 iAliasHostAddress = iAliasInterfaceIndex = 0; |
|
86 iAgentProcess = NULL; |
|
87 } |
|
88 |
|
89 CSHacontroller::~CSHacontroller() |
|
90 { |
|
91 assert( iAgentProcess == NULL ); |
|
92 } |
|
93 |
|
94 int CSHacontroller::GetKey() |
|
95 { |
|
96 return iKey; |
|
97 } |
|
98 |
|
99 void CSHacontroller::SetKey( int aKey ) |
|
100 { |
|
101 iKey = aKey; |
|
102 } |
|
103 |
|
104 |
|
105 /**************************************************************************************** |
|
106 * |
|
107 * PUBLIC FUNCTION: cstr_createagent |
|
108 * |
|
109 ***************************************************************************************/ |
|
110 TResult CSHacontroller::cstr_createagent( void ) |
|
111 { |
|
112 TResult rv; |
|
113 |
|
114 // initialise the result |
|
115 rv.iServiceResult = ERR_NONE; |
|
116 rv.iSubComponentResult = 0; |
|
117 rv.iData0 = 0; |
|
118 rv.iData1 = 0; |
|
119 |
|
120 // create the virtual network |
|
121 rv = CreateVirtualNetwork(); |
|
122 if( rv.iServiceResult != ERR_NONE ) { |
|
123 return rv; |
|
124 } |
|
125 |
|
126 // create the interface alias |
|
127 rv = CreateAliasInterface(); |
|
128 if( rv.iServiceResult != ERR_NONE ) { |
|
129 RemoveVirtualNetwork(); |
|
130 return rv; |
|
131 } |
|
132 |
|
133 // create the dynamics config file |
|
134 rv = CreateDynamicsConfigFile(); |
|
135 if( rv.iServiceResult != ERR_NONE ) { |
|
136 RemoveVirtualNetwork(); |
|
137 RemoveAliasInterface(); |
|
138 return rv; |
|
139 } |
|
140 |
|
141 // done - success |
|
142 return rv; |
|
143 } |
|
144 |
|
145 |
|
146 /**************************************************************************************** |
|
147 * |
|
148 * PUBLIC FUNCTION: dstr_removeagent |
|
149 * |
|
150 ***************************************************************************************/ |
|
151 TResult CSHacontroller::dstr_removeagent( int aArgs, int *aDeleteInstance ) |
|
152 { |
|
153 TResult rv, rv_config, rv_interface, rv_vn; |
|
154 |
|
155 // initialise the result |
|
156 rv.iServiceResult = ERR_NONE; |
|
157 rv.iSubComponentResult = 0; |
|
158 rv.iData0 = 0; |
|
159 rv.iData1 = 0; |
|
160 |
|
161 // make sure that the proces isn't running |
|
162 if( iAgentProcess != NULL ) { |
|
163 *aDeleteInstance = 0; |
|
164 rv.iServiceResult = ERR_INVALIDSTATE; |
|
165 return rv; |
|
166 } |
|
167 |
|
168 // cleanup the virtual network |
|
169 rv_vn = RemoveVirtualNetwork(); |
|
170 |
|
171 // cleanup the dynamics config file |
|
172 rv_config = RemoveDynamicsConfigFile(); |
|
173 |
|
174 // cleanup the alias interface |
|
175 rv_interface = RemoveAliasInterface(); |
|
176 |
|
177 // check for errors |
|
178 if( rv_vn.iServiceResult != ERR_NONE ) { |
|
179 return rv_vn; |
|
180 } |
|
181 if( rv_config.iServiceResult != ERR_NONE ) { |
|
182 return rv_config; |
|
183 } |
|
184 if( rv_interface.iServiceResult != ERR_NONE ) { |
|
185 return rv_interface; |
|
186 } |
|
187 |
|
188 // done - success |
|
189 return rv; |
|
190 } |
|
191 |
|
192 |
|
193 /**************************************************************************************** |
|
194 * |
|
195 * PUBLIC FUNCTION: startmobileagent |
|
196 * |
|
197 ***************************************************************************************/ |
|
198 TResult CSHacontroller::startmobileagent( int aArgs ) |
|
199 { |
|
200 TResult rv; |
|
201 int errcode; |
|
202 TCAProcessError perr; |
|
203 char command_line_str[MAXCOMMANDLINELENGTH]; |
|
204 |
|
205 // initialise the result |
|
206 rv.iServiceResult = ERR_NONE; |
|
207 rv.iSubComponentResult = 0; |
|
208 rv.iData0 = 0; |
|
209 rv.iData1 = 0; |
|
210 |
|
211 // check that there is currently no process |
|
212 if( iAgentProcess != NULL ) { |
|
213 rv.iServiceResult = ERR_INVALIDSTATE; |
|
214 rv.iSubComponentResult = 0; |
|
215 rv.iData0 = 0; |
|
216 return rv; |
|
217 } |
|
218 |
|
219 // create the new process object |
|
220 iAgentProcess = new CAProcess(); |
|
221 assert( iAgentProcess != NULL ); |
|
222 |
|
223 // construct the command line |
|
224 snprintf( command_line_str, MAXCOMMANDLINELENGTH, "%s%s", MOBILE_AGENT_COMMAND_LINE, iDynamicsConfigFile.GetLocalFilename() ); |
|
225 |
|
226 // start the actual process |
|
227 perr = iAgentProcess->StartProcess( command_line_str, &errcode, false, false, false ); |
|
228 if( perr != CAE_NONE ) { |
|
229 rv.iServiceResult = ERR_START_PROCESS_ERROR; |
|
230 rv.iSubComponentResult = (int)perr; |
|
231 rv.iData0 = errcode; |
|
232 delete iAgentProcess; |
|
233 iAgentProcess = NULL; |
|
234 return rv; |
|
235 } |
|
236 |
|
237 // done - success |
|
238 return rv; |
|
239 } |
|
240 |
|
241 |
|
242 /**************************************************************************************** |
|
243 * |
|
244 * PUBLIC FUNCTION: stopmobileagent |
|
245 * |
|
246 ***************************************************************************************/ |
|
247 TResult CSHacontroller::stopmobileagent( int aArgs ) |
|
248 { |
|
249 TResult rv; |
|
250 TCAProcessError perr; |
|
251 TProcessStatus pstatus; |
|
252 |
|
253 // initialise the result |
|
254 rv.iServiceResult = ERR_NONE; |
|
255 rv.iSubComponentResult = 0; |
|
256 rv.iData0 = 0; |
|
257 rv.iData1 = 0; |
|
258 |
|
259 // if the process isn't started then invalid state |
|
260 if( iAgentProcess == NULL ) { |
|
261 rv.iServiceResult = ERR_INVALIDSTATE; |
|
262 return rv; |
|
263 } |
|
264 |
|
265 // if the process isn't running then it has died outside the scope of this controller, clean up the state, return an error since |
|
266 // this is noteworthy and should be either expected or not happen. |
|
267 perr = iAgentProcess->GetProcessStatus( &pstatus ); |
|
268 assert( perr == CAE_NONE ); |
|
269 if( pstatus != PS_STARTED ) { |
|
270 assert( (pstatus == PS_STOPPED) || (pstatus == PS_ABANDONNED) ); |
|
271 delete iAgentProcess; |
|
272 iAgentProcess = NULL; |
|
273 rv.iServiceResult = ERR_PROCESS_TERMINATED_OUTSIDE_SCOPE; |
|
274 return rv; |
|
275 } |
|
276 |
|
277 // request the process to stop |
|
278 perr = iAgentProcess->RequestStop( SIGTERM ); |
|
279 if( perr != CAE_NONE ) { |
|
280 rv.iServiceResult = ERR_STOP_PROCESS_ERROR; |
|
281 rv.iSubComponentResult = (int)perr; |
|
282 return rv; |
|
283 } |
|
284 |
|
285 // wait for the process to stop |
|
286 perr = iAgentProcess->WaitForProcessToTerminate( -1 ); |
|
287 if( perr != CAE_NONE ) { |
|
288 rv.iServiceResult = ERR_WAIT_PROCESS_ERROR; |
|
289 rv.iSubComponentResult = (int)perr; |
|
290 return rv; |
|
291 } |
|
292 |
|
293 // remove the process |
|
294 delete iAgentProcess; |
|
295 iAgentProcess = NULL; |
|
296 |
|
297 // done - success |
|
298 return rv; |
|
299 } |
|
300 |
|
301 |
|
302 /**************************************************************************************** |
|
303 * |
|
304 * PUBLIC FUNCTION: getmobileagentstatus |
|
305 * |
|
306 ***************************************************************************************/ |
|
307 TResult CSHacontroller::getmobileagentstatus( int aArgs ) |
|
308 { |
|
309 TResult rv; |
|
310 TCAProcessError perr; |
|
311 TProcessStatus pstatus; |
|
312 |
|
313 // initialise the result |
|
314 rv.iServiceResult = ERR_NONE; |
|
315 rv.iSubComponentResult = 0; |
|
316 rv.iData0 = 0; |
|
317 rv.iData1 = 0; |
|
318 |
|
319 // if the process doesn't exist then we return PS_INVALID |
|
320 if( iAgentProcess == NULL ) { |
|
321 rv.iData0 = PS_INVALID; |
|
322 return rv; |
|
323 } |
|
324 |
|
325 // otherwise just return whatever iAgentProcess->GetProcessStatus() returns |
|
326 perr = iAgentProcess->GetProcessStatus( &pstatus ); |
|
327 assert( perr == CAE_NONE ); |
|
328 rv.iData0 = (int)pstatus; |
|
329 return rv; |
|
330 } |
|
331 |
|
332 |
|
333 /**************************************************************************************** |
|
334 * |
|
335 * PUBLIC FUNCTION: setsingleoption |
|
336 * |
|
337 ***************************************************************************************/ |
|
338 TResult CSHacontroller::setsingleoption( TOptionDesc aArgs ) |
|
339 { |
|
340 TResult rv; |
|
341 int errcode; |
|
342 TDCFError cerr; |
|
343 |
|
344 // initialise the result |
|
345 rv.iServiceResult = ERR_NONE; |
|
346 rv.iSubComponentResult = 0; |
|
347 rv.iData0 = 0; |
|
348 rv.iData1 = 0; |
|
349 |
|
350 // make sure that the process isn't running |
|
351 if( iAgentProcess != NULL ) { |
|
352 rv.iServiceResult = ERR_INVALIDSTATE; |
|
353 return rv; |
|
354 } |
|
355 |
|
356 // modify the config file |
|
357 cerr = iDynamicsConfigFile.SetSingleOption( aArgs.iOptionToken, aArgs.iOptionValue, &errcode ); |
|
358 if( cerr != DCE_NONE ) { |
|
359 rv.iServiceResult = ERR_CONFIG_FILE_ERROR; |
|
360 rv.iSubComponentResult = (int)cerr; |
|
361 rv.iData0 = errcode; |
|
362 return rv; |
|
363 } |
|
364 |
|
365 // return success |
|
366 return rv; |
|
367 } |
|
368 |
|
369 |
|
370 /**************************************************************************************** |
|
371 * |
|
372 * PUBLIC FUNCTION: removesingleoption |
|
373 * |
|
374 ***************************************************************************************/ |
|
375 TResult CSHacontroller::removesingleoption( TOptionDesc aArgs ) |
|
376 { |
|
377 TResult rv; |
|
378 int errcode; |
|
379 TDCFError cerr; |
|
380 |
|
381 // initialise the result |
|
382 rv.iServiceResult = ERR_NONE; |
|
383 rv.iSubComponentResult = 0; |
|
384 rv.iData0 = 0; |
|
385 rv.iData1 = 0; |
|
386 |
|
387 // make sure that the process isn't running |
|
388 if( iAgentProcess != NULL ) { |
|
389 rv.iServiceResult = ERR_INVALIDSTATE; |
|
390 return rv; |
|
391 } |
|
392 |
|
393 // modify the config file |
|
394 cerr = iDynamicsConfigFile.RemoveSingleOption( aArgs.iOptionToken, &errcode ); |
|
395 if( cerr != DCE_NONE ) { |
|
396 rv.iServiceResult = ERR_CONFIG_FILE_ERROR; |
|
397 rv.iSubComponentResult = (int)cerr; |
|
398 rv.iData0 = errcode; |
|
399 return rv; |
|
400 } |
|
401 |
|
402 // return success |
|
403 return rv; |
|
404 } |
|
405 |
|
406 |
|
407 /**************************************************************************************** |
|
408 * |
|
409 * PUBLIC FUNCTION: addlistoption |
|
410 * |
|
411 ***************************************************************************************/ |
|
412 TResult CSHacontroller::addlistoption( TOptionDesc aArgs ) |
|
413 { |
|
414 TResult rv; |
|
415 int errcode; |
|
416 TDCFError cerr; |
|
417 |
|
418 // initialise the result |
|
419 rv.iServiceResult = ERR_NONE; |
|
420 rv.iSubComponentResult = 0; |
|
421 rv.iData0 = 0; |
|
422 rv.iData1 = 0; |
|
423 |
|
424 // make sure that the process isn't running |
|
425 if( iAgentProcess != NULL ) { |
|
426 rv.iServiceResult = ERR_INVALIDSTATE; |
|
427 return rv; |
|
428 } |
|
429 |
|
430 // modify the config file |
|
431 cerr = iDynamicsConfigFile.AddListOption( aArgs.iOptionBlockStart, aArgs.iOptionBlockEnd, aArgs.iOptionValue, &errcode ); |
|
432 if( cerr != DCE_NONE ) { |
|
433 rv.iServiceResult = ERR_CONFIG_FILE_ERROR; |
|
434 rv.iSubComponentResult = (int)cerr; |
|
435 rv.iData0 = errcode; |
|
436 return rv; |
|
437 } |
|
438 |
|
439 // return success |
|
440 return rv; |
|
441 } |
|
442 |
|
443 |
|
444 /**************************************************************************************** |
|
445 * |
|
446 * PUBLIC FUNCTION: removelistoption |
|
447 * |
|
448 ***************************************************************************************/ |
|
449 TResult CSHacontroller::removelistoption( TOptionDesc aArgs ) |
|
450 { |
|
451 TResult rv; |
|
452 int errcode; |
|
453 TDCFError cerr; |
|
454 |
|
455 // initialise the result |
|
456 rv.iServiceResult = ERR_NONE; |
|
457 rv.iSubComponentResult = 0; |
|
458 rv.iData0 = 0; |
|
459 rv.iData1 = 0; |
|
460 |
|
461 // make sure that the process isn't running |
|
462 if( iAgentProcess != NULL ) { |
|
463 rv.iServiceResult = ERR_INVALIDSTATE; |
|
464 rv.iSubComponentResult = 0; |
|
465 rv.iData0 = 0; |
|
466 return rv; |
|
467 } |
|
468 |
|
469 // modify the config file |
|
470 cerr = iDynamicsConfigFile.RemoveListOption( aArgs.iOptionBlockStart, aArgs.iOptionBlockEnd, aArgs.iOptionToken, &errcode ); |
|
471 if( cerr != DCE_NONE ) { |
|
472 rv.iServiceResult = ERR_CONFIG_FILE_ERROR; |
|
473 rv.iSubComponentResult = (int)cerr; |
|
474 rv.iData0 = errcode; |
|
475 return rv; |
|
476 } |
|
477 |
|
478 // return success |
|
479 return rv; |
|
480 } |
|
481 |
|
482 |
|
483 /**************************************************************************************** |
|
484 * |
|
485 * PUBLIC FUNCTION: getstatus |
|
486 * |
|
487 ***************************************************************************************/ |
|
488 THaStatus CSHacontroller::getstatus( int aArgs ) |
|
489 { |
|
490 TResult res; |
|
491 THaStatus rv; |
|
492 TDynamicsCallInfo cres; |
|
493 THomeAgentStatusInfo home_agent_info; |
|
494 |
|
495 // init the return value |
|
496 memset( &rv, 0, sizeof(rv) ); |
|
497 rv.iCallResult.iServiceResult = ERR_NONE; |
|
498 |
|
499 // add the info about the virtual network |
|
500 rv.iHomeAgentAddress = inet_addr( iAliasInterfaceAddress.c_str() ); |
|
501 rv.iVirtualNetworkStartAddress = iVirtualNetworkSegmentAddress; |
|
502 rv.iVirtualNetworkSize = iVirtualNetworkSegmentSize; |
|
503 |
|
504 // if the agent is not running then we are done |
|
505 res = is_agent_running(); |
|
506 if( res.iServiceResult != ERR_NONE ) { |
|
507 return rv; |
|
508 } |
|
509 |
|
510 // make the call to dynamics |
|
511 cres = iDynamicsCommand.HomeAgentGetStatus( &home_agent_info ); |
|
512 if( cres.iResult != DC_SUCCESS ) { |
|
513 set_dynamics_error( &(rv.iCallResult), &cres ); |
|
514 return rv; |
|
515 } |
|
516 |
|
517 // set the result |
|
518 rv.iAdvertisementsSent = home_agent_info.iAdvertisementsSent; |
|
519 rv.iDiscardedMalformed = home_agent_info.iDiscardedMalformed; |
|
520 rv.iDiscardedUnknownExtension = home_agent_info.iDiscardedUnknownExtension; |
|
521 rv.iDiscardedVendor = home_agent_info.iDiscardedVendor; |
|
522 rv.iRequestsAccepted = home_agent_info.iRequestsAccepted; |
|
523 rv.iRequestsRejected = home_agent_info.iRequestsRejected; |
|
524 rv.iTunnelCount = home_agent_info.iTunnelCount; |
|
525 return rv; |
|
526 } |
|
527 |
|
528 |
|
529 /**************************************************************************************** |
|
530 * |
|
531 * PUBLIC FUNCTION: destroytunnelid |
|
532 * |
|
533 ***************************************************************************************/ |
|
534 TResult CSHacontroller::destroytunnelid( THaTunnelID aArgs ) |
|
535 { |
|
536 TResult rv; |
|
537 TDynamicsCallInfo cres; |
|
538 |
|
539 // init the return value |
|
540 memset( &rv, 0, sizeof(rv) ); |
|
541 rv.iServiceResult = ERR_NONE; |
|
542 |
|
543 // check that the agent is running |
|
544 rv = is_agent_running(); |
|
545 if( rv.iServiceResult != ERR_NONE ) { |
|
546 return rv; |
|
547 } |
|
548 |
|
549 // make the call to dynamics |
|
550 cres = iDynamicsCommand.HomeAgentDestroyTunnel( aArgs.iMobileNodeAddress ); |
|
551 if( cres.iResult != DC_SUCCESS ) { |
|
552 set_dynamics_error( &rv, &cres ); |
|
553 return rv; |
|
554 } |
|
555 |
|
556 // done |
|
557 return rv; |
|
558 } |
|
559 |
|
560 |
|
561 /**************************************************************************************** |
|
562 * |
|
563 * PUBLIC FUNCTION: listtunnels |
|
564 * |
|
565 ***************************************************************************************/ |
|
566 THaTunnelList CSHacontroller::listtunnels( int aArgs ) |
|
567 { |
|
568 TResult res; |
|
569 THaTunnelList rv = { 0, NULL }; |
|
570 TDynamicsCallInfo cres; |
|
571 unsigned int tunnel_list[MAXTUNNELS]; |
|
572 int tunnel_count = MAXTUNNELS, i; |
|
573 |
|
574 // check that the agent is running |
|
575 res = is_agent_running(); |
|
576 if( res.iServiceResult != ERR_NONE ) { |
|
577 return rv; |
|
578 } |
|
579 |
|
580 // make the call to dynamics |
|
581 cres = iDynamicsCommand.HomeAgentGetTunnels( &tunnel_count, tunnel_list ); |
|
582 if( cres.iResult != DC_SUCCESS ) { |
|
583 return rv; |
|
584 } |
|
585 |
|
586 // allocate memory for the list |
|
587 rv.THaTunnelList_len = tunnel_count; |
|
588 rv.THaTunnelList_val = (THaTunnelID*)calloc( tunnel_count, sizeof(THaTunnelID) ); |
|
589 assert( rv.THaTunnelList_val != NULL ); |
|
590 |
|
591 // now return the information |
|
592 for( i = 0; i < tunnel_count; i++ ) { |
|
593 (rv.THaTunnelList_val)[i].iAgentID = 0; |
|
594 (rv.THaTunnelList_val)[i].iMobileNodeAddress = tunnel_list[i]; |
|
595 } |
|
596 |
|
597 // done - success |
|
598 return rv; |
|
599 } |
|
600 |
|
601 |
|
602 /**************************************************************************************** |
|
603 * |
|
604 * PUBLIC FUNCTION: gettunnelinfo |
|
605 * |
|
606 ***************************************************************************************/ |
|
607 THaTunnelInfo CSHacontroller::gettunnelinfo( TGetTunnelRequest aArgs ) |
|
608 { |
|
609 THaTunnelInfo rv; |
|
610 TDynamicsCallInfo cres; |
|
611 THomeAgentTunnelInfo hati; |
|
612 |
|
613 // init the result |
|
614 memset( &rv, 0, sizeof(rv) ); |
|
615 rv.iCallResult.iServiceResult = ERR_NONE; |
|
616 |
|
617 // check that the agent is running |
|
618 rv.iCallResult = is_agent_running(); |
|
619 if( rv.iCallResult.iServiceResult != ERR_NONE ) { |
|
620 return rv; |
|
621 } |
|
622 |
|
623 // make the call to dynamics |
|
624 cres = iDynamicsCommand.HomeAgentGetTunnelInfo( aArgs.iMobileNodeAddress, &hati ); |
|
625 if( cres.iResult != DC_SUCCESS ) { |
|
626 set_dynamics_error( &(rv.iCallResult), &cres ); |
|
627 return rv; |
|
628 } |
|
629 |
|
630 // set the info |
|
631 rv.iCareofAddress = hati.iCareofAddress; |
|
632 rv.iCreationTime = hati.iCreationTime; |
|
633 rv.iExpirationTime = hati.iExpirationTime; |
|
634 rv.iHomeAgentAddress = hati.iHomeAgentAddress; |
|
635 rv.iLastTimestamp = hati.iLastTimestamp; |
|
636 rv.iMobileNodeAddress = hati.iMobileNodeAddress; |
|
637 rv.iRefreshTime = hati.iRefreshTime; |
|
638 rv.iSPI = hati.iSPI; |
|
639 rv.iTimeout = hati.iTimeout; |
|
640 return rv; |
|
641 } |
|
642 |
|
643 |
|
644 /**************************************************************************************** |
|
645 * |
|
646 * PUBLIC FUNCTION: settimeout |
|
647 * |
|
648 ***************************************************************************************/ |
|
649 void CSHacontroller::settimeout( TTimeoutRequest aArgs ) |
|
650 { |
|
651 iDynamicsCallTimeout = aArgs.iTimeout; |
|
652 } |
|
653 |
|
654 |
|
655 /**************************************************************************************** |
|
656 * |
|
657 * PRIVATE FUNCTION: CreateDynamicsConfigFile |
|
658 * |
|
659 ***************************************************************************************/ |
|
660 TResult CSHacontroller::CreateDynamicsConfigFile() |
|
661 { |
|
662 TResult rv; |
|
663 int errcode; |
|
664 TDCFError config_file_error; |
|
665 char dynamics_config[MAXINTERFACECONFIGENTRY]; |
|
666 struct in_addr iaddr; |
|
667 TStartupInfo startupinfo; |
|
668 |
|
669 // initialise the rv - always be optimistic! |
|
670 rv.iServiceResult = ERR_NONE; |
|
671 rv.iSubComponentResult = 0; |
|
672 rv.iData0 = 0; |
|
673 |
|
674 // set the reference file |
|
675 config_file_error = iDynamicsConfigFile.SetReferenceFile( TEMPLATE_HA_CONFIG_FILE ); |
|
676 if( config_file_error != DCE_NONE ) { |
|
677 rv.iServiceResult = ERR_CONFIG_FILE_ERROR; |
|
678 rv.iSubComponentResult = (int)config_file_error; |
|
679 return rv; |
|
680 } |
|
681 |
|
682 // create a local copy |
|
683 config_file_error = iDynamicsConfigFile.CreateLocalCopy( &errcode ); |
|
684 if( config_file_error != DCE_NONE ) { |
|
685 rv.iServiceResult = ERR_CONFIG_FILE_ERROR; |
|
686 rv.iSubComponentResult = (int)config_file_error; |
|
687 rv.iData0 = errcode; |
|
688 return rv; |
|
689 } |
|
690 |
|
691 // get the startup info |
|
692 startupinfo = CSvcHacontroller::GetStartupInfo(); |
|
693 |
|
694 // add the listen interface |
|
695 snprintf( dynamics_config, MAXINTERFACECONFIGENTRY, "eth%d:%d 0 1 30", startupinfo.iBaseInterfaceIndex, iAliasInterfaceIndex ); |
|
696 config_file_error = iDynamicsConfigFile.AddListOption( "INTERFACES_BEGIN", "INTERFACES_END", dynamics_config, &errcode ); |
|
697 if( config_file_error != DCE_NONE ) { |
|
698 rv.iServiceResult = ERR_CONFIG_FILE_ERROR; |
|
699 rv.iSubComponentResult = (int)config_file_error; |
|
700 rv.iData0 = errcode; |
|
701 iDynamicsConfigFile.RemoveLocalCopy( &errcode ); |
|
702 return rv; |
|
703 } |
|
704 |
|
705 // add the home network addresses to the authorized list |
|
706 iaddr.ADDRESS_INTEGER = iVirtualNetworkSegmentAddress; |
|
707 snprintf( dynamics_config, MAXINTERFACECONFIGENTRY, "1000 %s/%d", inet_ntoa(iaddr), iVirtualNetworkSegmentNetmaskBitcount ); |
|
708 config_file_error = iDynamicsConfigFile.AddListOption( "AUTHORIZEDLIST_BEGIN", "AUTHORIZEDLIST_END", dynamics_config, &errcode ); |
|
709 if( config_file_error != DCE_NONE ) { |
|
710 rv.iServiceResult = ERR_CONFIG_FILE_ERROR; |
|
711 rv.iSubComponentResult = (int)config_file_error; |
|
712 rv.iData0 = errcode; |
|
713 iDynamicsConfigFile.RemoveLocalCopy( &errcode ); |
|
714 return rv; |
|
715 } |
|
716 |
|
717 // done |
|
718 return rv; |
|
719 } |
|
720 |
|
721 |
|
722 /**************************************************************************************** |
|
723 * |
|
724 * PRIVATE FUNCTION: RemoveDynamicsConfigFile |
|
725 * |
|
726 ***************************************************************************************/ |
|
727 TResult CSHacontroller::RemoveDynamicsConfigFile() |
|
728 { |
|
729 TResult rv; |
|
730 TDCFError terr; |
|
731 int errcode; |
|
732 |
|
733 // initialise the rv - always be optimistic! |
|
734 rv.iServiceResult = ERR_NONE; |
|
735 rv.iSubComponentResult = 0; |
|
736 rv.iData0 = 0; |
|
737 |
|
738 // clean up the config file |
|
739 terr = iDynamicsConfigFile.RemoveLocalCopy( &errcode ); |
|
740 if( terr != DCE_NONE ) { |
|
741 rv.iServiceResult = ERR_CONFIG_FILE_ERROR; |
|
742 rv.iSubComponentResult = (int)terr; |
|
743 rv.iData0 = errcode; |
|
744 return rv; |
|
745 } |
|
746 |
|
747 // done |
|
748 return rv; |
|
749 } |
|
750 |
|
751 |
|
752 /**************************************************************************************** |
|
753 * |
|
754 * PRIVATE FUNCTION: CreateAliasInterface |
|
755 * |
|
756 ***************************************************************************************/ |
|
757 TResult CSHacontroller::CreateAliasInterface() |
|
758 { |
|
759 TResult rv; |
|
760 int errcode; |
|
761 CIntegerAllocator *alias_host_address_allocator; |
|
762 TStartupInfo startup_info; |
|
763 TInterfaceAliasError interface_alias_error; |
|
764 |
|
765 // initialise the rv - always be optimistic! |
|
766 rv.iServiceResult = ERR_NONE; |
|
767 rv.iSubComponentResult = 0; |
|
768 rv.iData0 = 0; |
|
769 |
|
770 // get the host address allocator |
|
771 alias_host_address_allocator = CSvcHacontroller::GetAliasHostAddressAllocator(); |
|
772 |
|
773 // get a host address |
|
774 assert( alias_host_address_allocator != NULL ); |
|
775 iAliasHostAddress = alias_host_address_allocator->AllocateInteger(); |
|
776 if( iAliasHostAddress == -1 ) { |
|
777 rv.iServiceResult = ERR_NO_MORE_INTERFACES; |
|
778 return rv; |
|
779 } |
|
780 // fprintf( stderr, "DEBUG: iAliasHostAddress = %d\n", iAliasHostAddress ); |
|
781 |
|
782 // get the startup info |
|
783 startup_info = CSvcHacontroller::GetStartupInfo(); |
|
784 |
|
785 // create an alias |
|
786 interface_alias_error = iAgentInterface.CreateNewInterfaceAlias( startup_info.iBaseInterfaceIndex, |
|
787 startup_info.iBaseInterfaceNetworkMask, |
|
788 iAliasHostAddress, &iAliasInterfaceIndex, &errcode ); |
|
789 if( interface_alias_error != IE_NONE ) { |
|
790 rv.iServiceResult = ERR_CREATE_INTERFACE_ERROR; |
|
791 rv.iSubComponentResult = (int)interface_alias_error; |
|
792 rv.iData0 = errcode; |
|
793 alias_host_address_allocator->FreeInteger( iAliasHostAddress ); |
|
794 return rv; |
|
795 } |
|
796 |
|
797 // get the complete interface address as a string |
|
798 interface_alias_error = iAgentInterface.GetInterfaceAddress( &iAliasInterfaceAddress ); |
|
799 assert( interface_alias_error == IE_NONE ); |
|
800 |
|
801 // done success |
|
802 return rv; |
|
803 } |
|
804 |
|
805 |
|
806 /**************************************************************************************** |
|
807 * |
|
808 * PRIVATE FUNCTION: RemoveAliasInterface |
|
809 * |
|
810 ***************************************************************************************/ |
|
811 TResult CSHacontroller::RemoveAliasInterface() |
|
812 { |
|
813 int err, errcode; |
|
814 TResult rv; |
|
815 TInterfaceAliasError interface_alias_error; |
|
816 CIntegerAllocator *alias_host_address_allocator; |
|
817 |
|
818 // initialise the rv - always be optimistic! |
|
819 rv.iServiceResult = ERR_NONE; |
|
820 rv.iSubComponentResult = 0; |
|
821 rv.iData0 = 0; |
|
822 |
|
823 // destroy the interface alias |
|
824 interface_alias_error = iAgentInterface.DestroyInterfaceAlias( &errcode ); |
|
825 if( interface_alias_error != IE_NONE ) { |
|
826 rv.iServiceResult = ERR_DESTROY_INTERFACE_ERROR; |
|
827 rv.iSubComponentResult = (int)interface_alias_error; |
|
828 rv.iData0 = errcode; |
|
829 return rv; |
|
830 } |
|
831 |
|
832 // get the host address allocator |
|
833 alias_host_address_allocator = CSvcHacontroller::GetAliasHostAddressAllocator(); |
|
834 |
|
835 // free the host address |
|
836 err = alias_host_address_allocator->FreeInteger( iAliasHostAddress ); |
|
837 assert( err == 0 ); |
|
838 |
|
839 // done |
|
840 iAliasHostAddress = iAliasInterfaceIndex = 0; |
|
841 return rv; |
|
842 } |
|
843 |
|
844 |
|
845 /**************************************************************************************** |
|
846 * |
|
847 * PRIVATE FUNCTION: CreateVirtualNetwork |
|
848 * |
|
849 ***************************************************************************************/ |
|
850 TResult CSHacontroller::CreateVirtualNetwork() |
|
851 { |
|
852 TResult rv; |
|
853 int segment_size, err, segment_netmask_bitcount; |
|
854 CNetworkPartitionManager *virtual_network_partition_allocator; |
|
855 |
|
856 // init the rv |
|
857 memset( &rv, 0, sizeof(rv) ); |
|
858 rv.iServiceResult = ERR_NONE; |
|
859 |
|
860 // get the virtual network partition allocator |
|
861 virtual_network_partition_allocator = CSvcHacontroller::GetNetworkPartitionManager(); |
|
862 assert( virtual_network_partition_allocator != NULL ); |
|
863 |
|
864 // get a virtual network partition to use |
|
865 err = virtual_network_partition_allocator->AllocateNetworkSegment( &segment_netmask_bitcount, &segment_size ); |
|
866 if( err == -1 ) { |
|
867 rv.iServiceResult = ERR_NO_MORE_VIRTUAL_NETWORKS; |
|
868 return rv; |
|
869 } |
|
870 |
|
871 // save this information |
|
872 iVirtualNetworkSegmentAddress = err; |
|
873 iVirtualNetworkSegmentSize = segment_size; |
|
874 iVirtualNetworkSegmentNetmaskBitcount = segment_netmask_bitcount; |
|
875 |
|
876 // done - ok |
|
877 rv.iServiceResult = ERR_NONE; |
|
878 return rv; |
|
879 } |
|
880 |
|
881 |
|
882 /**************************************************************************************** |
|
883 * |
|
884 * PRIVATE FUNCTION: RemoveVirtualNetwork |
|
885 * |
|
886 ***************************************************************************************/ |
|
887 TResult CSHacontroller::RemoveVirtualNetwork() |
|
888 { |
|
889 int err; |
|
890 TResult rv; |
|
891 CNetworkPartitionManager *virtual_network_partition_allocator; |
|
892 |
|
893 // init the rv |
|
894 memset( &rv, 0, sizeof(rv) ); |
|
895 rv.iServiceResult = ERR_NONE; |
|
896 |
|
897 // get the virtual network partition allocator |
|
898 virtual_network_partition_allocator = CSvcHacontroller::GetNetworkPartitionManager(); |
|
899 assert( virtual_network_partition_allocator != NULL ); |
|
900 |
|
901 // free the network address |
|
902 err = virtual_network_partition_allocator->FreeNetworkSegment( iVirtualNetworkSegmentAddress ); |
|
903 assert( err == 0 ); |
|
904 |
|
905 // clear-up the state |
|
906 iVirtualNetworkSegmentAddress = iVirtualNetworkSegmentSize = 0; |
|
907 |
|
908 // done |
|
909 rv.iServiceResult = ERR_NONE; |
|
910 return rv; |
|
911 } |
|
912 |
|
913 |
|
914 /**************************************************************************************** |
|
915 * |
|
916 * PRIVATE FUNCTION: is_agent_running |
|
917 * |
|
918 ***************************************************************************************/ |
|
919 TResult CSHacontroller::is_agent_running() |
|
920 { |
|
921 TResult rv; |
|
922 TCAProcessError perr; |
|
923 TProcessStatus pstatus; |
|
924 |
|
925 // init the rv |
|
926 memset( &rv, 0, sizeof(rv) ); |
|
927 rv.iServiceResult = ERR_NONE; |
|
928 |
|
929 // check that the agent was running |
|
930 if( iAgentProcess == NULL ) { |
|
931 rv.iServiceResult = ERR_INVALIDSTATE; |
|
932 return rv; |
|
933 } |
|
934 |
|
935 // check that the agent is still runnning |
|
936 perr = iAgentProcess->GetProcessStatus( &pstatus ); |
|
937 assert( perr == CAE_NONE ); |
|
938 if( pstatus != PS_STARTED ) { |
|
939 rv.iServiceResult = ERR_INVALIDSTATE; |
|
940 return rv; |
|
941 } |
|
942 |
|
943 // done - success |
|
944 return rv; |
|
945 } |
|
946 |
|
947 |
|
948 /**************************************************************************************** |
|
949 * |
|
950 * PRIVATE FUNCTION: is_agent_running |
|
951 * |
|
952 ***************************************************************************************/ |
|
953 void CSHacontroller::set_dynamics_error( TResult *result, TDynamicsCallInfo *cres ) |
|
954 { |
|
955 result->iServiceResult = ERR_DYNAMICS_CALL_FAILED; |
|
956 result->iSubComponentResult = cres->iResult; |
|
957 result->iData0 = cres->iErrorCode; |
|
958 result->iData1 = cres->iErrorDetail; |
|
959 } |