1 //----------------------------------------------------------------------------
3 // Copyright (C) Intel Corporation, 2004 - 2006.
5 // File: RemoteControlSample.cpp
7 // Contents: Sample code for an IntelĀ® AMT Network client.
9 // Notes: this file contains routines that call (using SOAP)
10 // the RemoteControl functions of the Intel(R) AMT 2.0 as
11 // defined in the "Intel(R) AMT Network Design Guide".
13 //----------------------------------------------------------------------------
15 #include "CommonDefinitions.h"
16 #include "RemoteControlTypes.h"
17 #include "RemoteControlSoapBinding.nsmap"
22 void Usage(char *cmd);
23 bool GetUserValues(uint8 *&command, uint32 *&ianaOemNumber,
24 uint8 *&specialCommand, uint16 *&specialCommandParameter,
25 uint16 *&bootOptions, uint16 *&OEMParameters);
26 void DisplaySystemCapabilities(uint8 specialCommandsSupported);
27 void DisplaySpecialCommand(uint16 specialCommandsSupported);
28 void DisplaySystemFirmwareCapabilities(uint32 systemFirmwareCapabilities);
29 void DisplayOemDefinedCapabilities(uint32 OemDefinedCapabilities);
30 bool ExecuteGetSystemPowerstate(Soap *server, bool verbose = true);
31 bool ExecuteGetRemoteControlCapabilities(Soap *server, bool verbose = true);
32 bool ExecuteRemoteControl(Soap *server, bool default_val = false, uint8 icommand=Reset);
33 bool MainFlow(Soap *server,int option,bool verbose);
34 bool ValidateOption(char *option, int *parameter);
37 * This is the main entry point
39 int main(int argc, char* argv[])
41 // Command line parameter
43 // Client certificate's name
44 char *certName = NULL;
46 // Password for keys file openning
47 char *certPass = NULL;
49 // True if an authentication scheme is Kerberos,
50 // otherwise the authentication scheme is digest
56 char *username = NULL;
58 char *password = NULL;
59 // Command line without app name and parameter
60 char **commandLine = NULL;
61 int commandLineLength = argc;
66 if( !GetOption(&commandLineLength,argv,
67 MIN_NUM_OF_CL_PARAMETERS,&option,&commandLine) ||
68 !ValidateOption(option,¶meter) ||
70 !ParseCommandLine(commandLineLength,commandLine,&target,
71 &certName,&certPass,&verbose,&username,&password)
73 !ParseCommandLine(commandLineLength,commandLine,&target,
74 &certName,NULL,&krb,&verbose,&username,&password)
82 // The last parameter should be true for local application
83 // and false for remote application
85 Soap server(target,certName,certPass,username,password);
87 Soap server(target,certName,username,password,false,krb);
90 if(MainFlow(&server,parameter,verbose) != true)
98 * Validates an option passed in the command line.
100 * option - command line option
101 * parameter - pointer to the variable that will hold
102 * type of the action the apllication
106 * false - on failure (command line option not recognized)
108 bool ValidateOption(char *option, int *parameter)
115 if(!strcmp(option,POWER))
117 *parameter = OPT_POWER;
119 else if(!strcmp(option,CAPABILITIES))
121 *parameter = OPT_CAPABILITIES;
123 else if(!strcmp(option,REMOTE))
125 *parameter = OPT_REMOTE;
127 else if(!strcmp(option,API_TEST))
129 *parameter = OPT_API_TEST;
131 else if(!strcmp(option,REDUCED_API_TEST))
133 *parameter = OPT_REDUCED_API_TEST;
143 * Function that performs the main flow of Remote Control sample
145 * soap - pointer to the runtime environment
146 * option - variable that holds type of the action the apllication
148 * verbose - boolean value for API test
153 bool MainFlow(Soap *server, int option, bool verbose)
159 status = ExecuteGetSystemPowerstate(server);
161 case OPT_CAPABILITIES:
162 status = ExecuteGetRemoteControlCapabilities(server);
165 status = ExecuteRemoteControl(server);
168 if((status = ExecuteGetSystemPowerstate(server,verbose)) == false)
172 if((status = ExecuteGetRemoteControlCapabilities(server,verbose)) == false)
176 /* Ensure that the machine is powered up before trying to
177 * 'reset' it, since a reset on a down node will fail. */
178 /*if ((status = ExecuteRemoteControl(server,true,PowerDown)) == false)
183 if ((status = ExecuteRemoteControl(server,true,PowerUp)) == false)
188 if ((status = ExecuteRemoteControl(server,true,Reset)) == false)
193 case OPT_REDUCED_API_TEST:
194 if((status = ExecuteGetSystemPowerstate(server,verbose)) == false)
198 if((status = ExecuteGetRemoteControlCapabilities(server,verbose)) == false)
211 * Prints a usage information for the user.
213 void Usage(char *cmd)
217 printf("\t %s <opt> [%s] [%s <name> %s <pass>] http[s]:", cmd, VERBOSE, CERT_NAME, CERT_PASS);
219 printf("\t %s <opt> [%s] [%s <username> %s <password>] [%s <name>] http[s]:",
220 cmd, VERBOSE, USER, PASS, CERT_NAME);
222 printf("//<Hostname>:<Port>/<RemoteControlUri> ");
224 printf("[%s <username> %s <password>]\n",USER,PASS);
226 printf("\nWhere <opt> is :\n");
227 printf("\t %s : GetSystemPowerstate\n",POWER);
228 printf("\t %s : GetRemoteControlCapabilities\n",CAPABILITIES);
229 printf("\t %s : RemoteControl\n",REMOTE);
230 printf("\t %s : perform API test\n",API_TEST);
231 printf("\t %s : perform API test without boot\n",REDUCED_API_TEST);
232 printf("\t To run API test in verbose mode include %s option\n", VERBOSE);
233 PrintAuthenticationNote();
234 printf("\nExample:\n");
235 printf("\t %s %s ", cmd, POWER);
236 printf("http://hostname:16992/RemoteControlService\n");
238 printf("\t %s %s %s MyCert %s Pass https://hostname:16993/RemoteControlService\n",
239 cmd, POWER, CERT_NAME, CERT_PASS);
241 printf("\t %s %s %s MyCert https://hostname:16993/RemoteControlService\n",
242 cmd, POWER, CERT_NAME);
247 * Queries (using SOAP) and display the system power state
249 * server - pointer to the runtime environment
250 * url - address of the web service
251 * verbose - boolean value for API test
256 bool ExecuteGetSystemPowerstate(Soap* server, bool verbose)
263 // gSOAP structures for handling
264 // request and response information
265 _rci__GetSystemPowerState request;
266 _rci__GetSystemPowerStateResponse response;
268 FunctionCall("GetSystemPowerState");
269 res = soap_call___rci__GetSystemPowerState(server->GetSoap(),
270 server->GetIp(),NULL, &request, &response);
273 CheckReturnStatus(res,
275 "GetSystemPowerState")) == true)
279 printf("\nSystemPowerstate is: %u\n", response.SystemPowerState);
291 * Queries (using SOAP) and display the Intel(R) AMT
292 * device remote control capabilities
294 * server - pointer to the runtime environment
295 * url - address of the web service
296 * verbose - boolean value for API test
301 bool ExecuteGetRemoteControlCapabilities(Soap* server, bool verbose)
308 // gSOAP structures for handling
309 // request and response information
310 _rci__GetRemoteControlCapabilities request;
311 _rci__GetRemoteControlCapabilitiesResponse response;
313 FunctionCall("GetRemoteControlCapabilities");
314 res = soap_call___rci__GetRemoteControlCapabilities(server->GetSoap(),
315 server->GetIp(),NULL, &request, &response);
317 if((status = CheckReturnStatus(res,response.Status,"GetRemoteControlCapabilities")) == true)
321 printf("\nRemote Control Capabilities\n");
322 printf("---------------------------------------\n");
324 printf("IanaOemNumber = %u\n", response.IanaOemNumber);
326 DisplayOemDefinedCapabilities(response.OemDefinedCapabilities);
329 DisplaySpecialCommand(response.SpecialCommandsSupported);
332 DisplaySystemCapabilities(response.SystemCapabilitiesSupported);
335 DisplaySystemFirmwareCapabilities(response.SystemFirmwareCapabilities);
349 * Controls remotely (using SOAP) the boot and power state of
350 * Intel(R) AMT-managed PC.
352 * server - pointer to the runtime environment
353 * url - address of the web service
354 * def_values - if false request values from user
359 bool ExecuteRemoteControl(Soap* server,bool def_values, uint8 icommand)
366 // gSOAP structures for handling
367 // request and response information
368 _rci__RemoteControl request;
369 _rci__RemoteControlResponse response;
372 uint8 *command = new uint8(icommand);
373 uint32 *ianaOemNumber = new uint32(IntelIanaNumber);
374 uint8 *specialCommand = NULL; //none
375 uint16 *oemParameter = NULL; //none
376 uint16 *bootOptions = NULL; //none
377 uint16 *specialCommandParameters = NULL; //none
381 // To use default values above, comment the following line.
382 if(!GetUserValues(command, ianaOemNumber, specialCommand, oemParameter,
383 bootOptions, specialCommandParameters))
394 request.Command = rci__RemoteControlCommandType__16;
397 request.Command = rci__RemoteControlCommandType__17;
400 request.Command = rci__RemoteControlCommandType__18;
402 case PowerCycleReset:
403 request.Command = rci__RemoteControlCommandType__19;
406 request.Command = rci__RemoteControlCommandType__33;
412 if(specialCommand == NULL)
414 request.SpecialCommand = NULL;
418 request.SpecialCommand = new rci__SpecialCommandType;
419 switch(*specialCommand)
422 *(request.SpecialCommand) = rci__SpecialCommandType__0;
425 *(request.SpecialCommand) = rci__SpecialCommandType__1;
427 case ForceHardDriveBoot:
428 *(request.SpecialCommand) = rci__SpecialCommandType__2;
430 case ForceHardDriveSafeModeBoot:
431 *(request.SpecialCommand) = rci__SpecialCommandType__3;
433 case ForceDiagnosticsBoot:
434 *(request.SpecialCommand) = rci__SpecialCommandType__4;
436 case ForceCdOrDvdBoot:
437 *(request.SpecialCommand) = rci__SpecialCommandType__5;
439 case IntelOemCommand:
440 *(request.SpecialCommand) = rci__SpecialCommandType__193;
447 request.IanaOemNumber = *ianaOemNumber;
448 request.BootOptions = bootOptions;
449 request.OEMparameters = oemParameter;
450 request.SpecialCommandParameter = specialCommandParameters;
452 FunctionCall("RemoteControl");
453 res = soap_call___rci__RemoteControl(server->GetSoap(),
454 server->GetIp(),NULL, &request, &response);
456 if((status = CheckReturnStatus(res,response.Status,"RemoteControl")) == true)
461 if(request.SpecialCommand != NULL)
463 delete request.SpecialCommand;
464 request.SpecialCommand = NULL;
468 // cleanup heap allocated memory
474 if(ianaOemNumber != NULL)
476 delete ianaOemNumber;
477 ianaOemNumber = NULL;
479 if(specialCommand != NULL)
481 delete specialCommand;
482 specialCommand = NULL;
484 if(oemParameter != NULL)
489 if(bootOptions != NULL)
494 if(specialCommandParameters != NULL)
496 delete specialCommandParameters;
497 specialCommandParameters = NULL;
504 * Get user's settings for the RemoteControl function
505 * Arguments & return values:
506 * command - specifies the boot or power state operation to be performed
507 * ianaOemNumber - specifies an IANA-assigned Enterprise Number
508 * specialCommand - specifies an optional modification to the boot behavior
509 * OemParameter - specifies IntelĀ® AMT proprietary boot options
510 * bootOptions - specifies standard boot options
511 * specialCommandParameters - specifies an optional modification to the
517 bool GetUserValues(uint8 *&command, uint32 *&ianaOemNumber,
518 uint8 *&specialCommand, uint16 *&oemParameter,
519 uint16 *&bootOptions, uint16 *&specialCommandParameters)
523 printf("Please specify the following parameters\n");
525 // Get mandatory parameters
528 printf("\n\tCommand");
529 printf("\n\t=======");
530 printf("\nPossible values:");
531 printf("\n\t%u (Reset)",Reset);
532 printf("\n\t%u (PowerUp)",PowerUp);
533 printf("\n\t%u (PowerDown)",PowerDown);
534 printf("\n\t%u (PowerCycleReset)",PowerCycleReset);
535 printf("\n\t%u (SetBootOptions)\n>",SetBootOptions);
538 // verify command value
542 tmp == PowerCycleReset ||
543 tmp == SetBootOptions)
546 if ( command == NULL )
548 command = new uint8();
550 *command = (uint8)tmp;
557 // If command is Set Boot Options, ianaOemNumber
558 // should be IntelIanaNumber.
559 if( *command == SetBootOptions )
562 if ( ianaOemNumber == NULL )
564 ianaOemNumber = new uint32();
567 printf("\nSetBootOptions command selected. ");
568 printf("Iana OEM Number is IntelIanaNumber (%u)\n",IntelIanaNumber);
570 *ianaOemNumber = (uint32)IntelIanaNumber;
576 printf("\n\tIana OEM Number");
577 printf("\n\t===============");
578 printf("\nPossible values:");
579 printf("\n\t%u (IntelIanaNumber)", IntelIanaNumber);
580 printf("\n\t%u (ASFIanaNumber)\n>", ASFIanaNumber);
583 // verify ianaOemNumber value
584 if ( tmp == IntelIanaNumber ||
585 tmp == ASFIanaNumber )
588 if ( ianaOemNumber == NULL )
590 ianaOemNumber = new uint32();
592 *ianaOemNumber = (uint32)tmp;
600 // if power down, all other parameters should not be sent.
601 if ( *command == PowerDown )
603 specialCommand = NULL;
606 specialCommandParameters = NULL;
610 // Get optional parameters
612 // Get Special Command
613 printf("\n\tSpecial Command");
614 printf("\n\t===============");
615 printf("\nPossible values:");
617 printf("\n\t%d (No Special Command)",-1);
618 printf("\n\t%u (NOP)",NOP);
619 printf("\n\t%u (ForcePxeBoot)",ForcePxeBoot);
620 printf("\n\t%u (ForceHardDriveBoot)",ForceHardDriveBoot);
621 printf("\n\t%u (ForceHardDriveSafeModeBoot)",ForceHardDriveSafeModeBoot);
622 printf("\n\t%u (ForceDiagnosticsBoot)",ForceDiagnosticsBoot);
623 printf("\n\t%u (ForceCdOrDvdBoot)",ForceCdOrDvdBoot);
624 printf("\n\t%u (IntelOemCommand)\n>",IntelOemCommand);
627 // verify specialCommand value
628 if ( tmp == NO_VALUE ||
630 tmp == ForcePxeBoot ||
631 tmp == ForceHardDriveBoot ||
632 tmp == ForceHardDriveSafeModeBoot ||
633 tmp == ForceDiagnosticsBoot ||
634 tmp == ForceCdOrDvdBoot ||
635 tmp == IntelOemCommand )
637 if ( tmp == NO_VALUE )
639 specialCommand = NULL;
641 else if(tmp == IntelOemCommand &&
642 *ianaOemNumber != IntelIanaNumber)
644 printf("Error: Special Command value %d is legal", IntelOemCommand);
645 printf(" only for IanaOemNumber value %d", IntelIanaNumber);
651 if ( specialCommand == NULL )
653 specialCommand = new uint8();
655 *specialCommand = (uint8)tmp;
664 // if ianaOemNumber is ASFIanaNumber, oemParameters should not be sent .
665 if ( *ianaOemNumber != IntelIanaNumber )
671 printf("\n\tOEM Parameters");
672 printf("\n\t==============");
673 printf("\nPossible values:");
674 printf("\n\t%d (No OEM Parameters)",-1);
675 printf("\n\t%d (Undefined OEM Parameter)",UndefinedOEMParameter);
676 printf("\n\t%u (UseSol)\n>",UseSol);
678 if ( tmp == NO_VALUE )
685 if ( oemParameter == NULL )
687 oemParameter = new uint16();
689 *oemParameter = (uint16) tmp;
693 // Get Special Command Parameters
694 printf("\n\tSpecial Command Parameters");
695 printf("\n\t==========================");
696 printf("\nPossible values:");
698 // Special Command is not equal to 0xC1 (IntelOemCommand)
699 if ( specialCommand == NULL ||
700 (specialCommand != NULL) && (*specialCommand != IntelOemCommand) )
702 printf("\n\tSpecial command not equal to %d",IntelOemCommand);
703 printf("\n\tSee ASF specification for the Special Command Parameter legal values");
704 printf("\n\n\t%d (No Special Command Parameter)\n>",-1);
707 // Special Command is 0xC1, hence Special Command Parameter
708 // used to augment the Special Command
711 printf("\n\t%d (No Special Command Parameter)",-1);
712 printf("\n\t%d (Undefined Special Command Parameter)",
713 UndefinedSpecialCommandParameter);
714 printf("\n\t%u (UseIderFloppy)",UseIderFloppy);
715 printf("\n\t%u (ReflashBios)",ReflashBios);
716 printf("\n\t%u (BiosSetup)",BiosSetup);
717 printf("\n\t%u (BiosPause)",BiosPause);
718 printf("\n\t%u (UseIderCD)\n",UseIderCD);
720 printf("\nYou can choose several options by using bitwise OR operation\n\n>");
723 // verify specialCommandParameters value
724 if ( (tmp != NO_VALUE) && (tmp & SpecialCommandParametersReservedBits) )
730 if ( tmp == NO_VALUE )
732 specialCommandParameters = NULL;
737 if ( specialCommandParameters == NULL )
739 specialCommandParameters = new uint16();
741 *specialCommandParameters = (uint16)tmp;
747 printf("\n\tBoot Options");
748 printf("\n\t============");
749 printf("\nPossible values:");
751 printf("\n\t%d (No boot options)", -1);
752 printf("\n\t%u (LockPowerButton)",LockPowerButton);
753 printf("\n\t%u (LockResetButton)",LockResetButton);
754 printf("\n\t%u (LockKeyboard)",LockKeyboard);
755 printf("\n\t%u (LockSleepButton)",LockSleepButton);
756 printf("\n\t%u (UserPasswordBypass)",UserPasswordBypass);
757 printf("\n\t%u (ForceProgressEvents)",ForceProgressEvents);
759 printf("\n\n\tFirmware Verbosity Options:");
760 printf( "\n\t---------------------------");
761 printf("\n\t%u (FirmwareVerbositySystemDefault)",FirmwareVerbositySystemDefault);
762 printf("\n\t%u (FirmwareVerbosityQuiet)",FirmwareVerbosityQuiet);
763 printf("\n\t%u (FirmwareVerbosityVerbose)",FirmwareVerbosityVerbose);
764 printf("\n\t%u (FirmwareVerbosityScreen)",FirmwareVerbosityScreen);
765 printf("\n\n\t%u (ConfigurationDataReset)\n",ConfigurationDataReset);
767 printf("\nYou can choose several options by using bitwise OR operation\n\n>");
770 // verify bootOptions value
771 if ( (tmp != NO_VALUE) && (tmp & BootOptionsReservedBits) )
777 if ( tmp == NO_VALUE )
784 if ( bootOptions == NULL )
786 bootOptions = new uint16();
788 *bootOptions = (uint16)tmp;
794 printf("Error: %u is an illegal value. Aborting.\n", tmp);
799 * Prints system capabilities supported by the Intel(R) AMT device
801 * systemCapabilitiesSupported - set of flags that indicate the values
802 * the Intel(R) AMT device supports in the
803 * Command parameter of the RemoteControl method
805 void DisplaySystemCapabilities(uint8 systemCapabilitiesSupported)
807 printf("\nSystemCapabilitiesSupported = %u", systemCapabilitiesSupported);
809 if ( systemCapabilitiesSupported & SuppPowerCycleReset )
811 printf("\nPowerCycleReset ");
813 if ( systemCapabilitiesSupported & SuppPowerDown )
815 printf("\nPowerDown ");
817 if ( systemCapabilitiesSupported & SuppPowerUp )
819 printf("\nPowerUp ");
821 if ( systemCapabilitiesSupported & SuppReset )
828 * Prints special commands supported by the Intel(R) AMT device
830 * specialCommandsSupported - set of flags that indicate the values
831 * the Intel(R) AMT device supports in the
832 * SpecialCommand parameter of the
833 * RemoteControl method
835 void DisplaySpecialCommand(uint16 specialCommandsSupported)
837 printf("\nSpecialCommandsSupported = %u", specialCommandsSupported);
839 if ( specialCommandsSupported & SuppForcePXEBoot )
841 printf("\nForcePXEBoot ");
843 if ( specialCommandsSupported & SuppForceHardDriveBoot )
845 printf("\nForceHardDriveBoot ");
847 if ( specialCommandsSupported & SuppForceHardDriveSafeModeBoot )
849 printf("\nForceHardDriveSafeModeBoot ");
851 if ( specialCommandsSupported & SuppForceDiagnosticBoot )
853 printf("\nForceDiagnosticBoot ");
855 if ( specialCommandsSupported & SuppForceCDorDVDBoot )
857 printf("\nForceCDorDVDBoot");
863 * Prints firmware capabilities supported by the Intel(R) AMT device
865 * systemCapabilitiesSupported - set of flags that indicate the values
866 * the Intel(R) AMT device supports in the
867 * BootOptions parameter of the RemoteControl
870 void DisplaySystemFirmwareCapabilities(uint32 systemFirmwareCapabilities)
872 printf("\nSystemFirmwareCapabilities = %u", systemFirmwareCapabilities);
874 if ( systemFirmwareCapabilities & SuppVerbosityScreenBlank )
876 printf("\nVerbosityScreenBlank ");
878 if ( systemFirmwareCapabilities & SuppPowerButtonLock )
880 printf("\nPowerButtonLock ");
882 if ( systemFirmwareCapabilities & SuppResetButtonLock )
884 printf("\nResetButtonLock ");
886 if ( systemFirmwareCapabilities & SuppKeyboardLock )
888 printf("\nKeyboardLock ");
890 if ( systemFirmwareCapabilities & SuppSleepButtonLock )
892 printf("\nSleepButtonLock ");
894 if ( systemFirmwareCapabilities & SuppUserPasswordBypass )
896 printf("\nUserPasswordBypass ");
898 if ( systemFirmwareCapabilities & SuppForcedProgressEvents )
900 printf("\nForcedProgressEvents ");
902 if ( systemFirmwareCapabilities & SuppVerbosityVerbose )
904 printf("\nVerbosityVerbose ");
906 if ( systemFirmwareCapabilities & SuppVerbosityQuiet )
908 printf("\nVerbosityQuiet ");
910 if ( systemFirmwareCapabilities & SuppConfigurationDataReset )
912 printf("\nConfigurationDataReset");
918 * Prints OEM defined capabilities supported by the Intel(R) AMT device
920 * systemCapabilitiesSupported - set of flags that indicate the values
921 * the Intel(R) AMT device supports in the
922 * OemParameters parameter of the RemoteControl
925 void DisplayOemDefinedCapabilities(uint32 oemDefinedCapabilities)
927 printf("\nOemDefinedCapabilities = %u", oemDefinedCapabilities);
929 if ( oemDefinedCapabilities & SuppIDER )
933 if ( oemDefinedCapabilities & SuppSOL )
937 if ( oemDefinedCapabilities & SuppBiosReflash )
939 printf("\nBiosReflash");
941 if ( oemDefinedCapabilities & SuppBiosSetup )
943 printf("\nBiosSetup");
945 if ( oemDefinedCapabilities & SuppBiosPause )
947 printf("\nBiosPause");