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,PowerUp)) == false)
182 if ((status = ExecuteRemoteControl(server,true,Reset)) == false)
187 case OPT_REDUCED_API_TEST:
188 if((status = ExecuteGetSystemPowerstate(server,verbose)) == false)
192 if((status = ExecuteGetRemoteControlCapabilities(server,verbose)) == false)
205 * Prints a usage information for the user.
207 void Usage(char *cmd)
211 printf("\t %s <opt> [%s] [%s <name> %s <pass>] http[s]:", cmd, VERBOSE, CERT_NAME, CERT_PASS);
213 printf("\t %s <opt> [%s] [%s <username> %s <password>] [%s <name>] http[s]:",
214 cmd, VERBOSE, USER, PASS, CERT_NAME);
216 printf("//<Hostname>:<Port>/<RemoteControlUri> ");
218 printf("[%s <username> %s <password>]\n",USER,PASS);
220 printf("\nWhere <opt> is :\n");
221 printf("\t %s : GetSystemPowerstate\n",POWER);
222 printf("\t %s : GetRemoteControlCapabilities\n",CAPABILITIES);
223 printf("\t %s : RemoteControl\n",REMOTE);
224 printf("\t %s : perform API test\n",API_TEST);
225 printf("\t %s : perform API test without boot\n",REDUCED_API_TEST);
226 printf("\t To run API test in verbose mode include %s option\n", VERBOSE);
227 PrintAuthenticationNote();
228 printf("\nExample:\n");
229 printf("\t %s %s ", cmd, POWER);
230 printf("http://hostname:16992/RemoteControlService\n");
232 printf("\t %s %s %s MyCert %s Pass https://hostname:16993/RemoteControlService\n",
233 cmd, POWER, CERT_NAME, CERT_PASS);
235 printf("\t %s %s %s MyCert https://hostname:16993/RemoteControlService\n",
236 cmd, POWER, CERT_NAME);
241 * Queries (using SOAP) and display the system power state
243 * server - pointer to the runtime environment
244 * url - address of the web service
245 * verbose - boolean value for API test
250 bool ExecuteGetSystemPowerstate(Soap* server, bool verbose)
257 // gSOAP structures for handling
258 // request and response information
259 _rci__GetSystemPowerState request;
260 _rci__GetSystemPowerStateResponse response;
262 FunctionCall("GetSystemPowerState");
263 res = soap_call___rci__GetSystemPowerState(server->GetSoap(),
264 server->GetIp(),NULL, &request, &response);
267 CheckReturnStatus(res,
269 "GetSystemPowerState")) == true)
273 printf("\nSystemPowerstate is: %u\n", response.SystemPowerState);
285 * Queries (using SOAP) and display the Intel(R) AMT
286 * device remote control capabilities
288 * server - pointer to the runtime environment
289 * url - address of the web service
290 * verbose - boolean value for API test
295 bool ExecuteGetRemoteControlCapabilities(Soap* server, bool verbose)
302 // gSOAP structures for handling
303 // request and response information
304 _rci__GetRemoteControlCapabilities request;
305 _rci__GetRemoteControlCapabilitiesResponse response;
307 FunctionCall("GetRemoteControlCapabilities");
308 res = soap_call___rci__GetRemoteControlCapabilities(server->GetSoap(),
309 server->GetIp(),NULL, &request, &response);
311 if((status = CheckReturnStatus(res,response.Status,"GetRemoteControlCapabilities")) == true)
315 printf("\nRemote Control Capabilities\n");
316 printf("---------------------------------------\n");
318 printf("IanaOemNumber = %u\n", response.IanaOemNumber);
320 DisplayOemDefinedCapabilities(response.OemDefinedCapabilities);
323 DisplaySpecialCommand(response.SpecialCommandsSupported);
326 DisplaySystemCapabilities(response.SystemCapabilitiesSupported);
329 DisplaySystemFirmwareCapabilities(response.SystemFirmwareCapabilities);
343 * Controls remotely (using SOAP) the boot and power state of
344 * Intel(R) AMT-managed PC.
346 * server - pointer to the runtime environment
347 * url - address of the web service
348 * def_values - if false request values from user
353 bool ExecuteRemoteControl(Soap* server,bool def_values, uint8 icommand)
360 // gSOAP structures for handling
361 // request and response information
362 _rci__RemoteControl request;
363 _rci__RemoteControlResponse response;
366 uint8 *command = new uint8(icommand);
367 uint32 *ianaOemNumber = new uint32(IntelIanaNumber);
368 uint8 *specialCommand = NULL; //none
369 uint16 *oemParameter = NULL; //none
370 uint16 *bootOptions = NULL; //none
371 uint16 *specialCommandParameters = NULL; //none
375 // To use default values above, comment the following line.
376 if(!GetUserValues(command, ianaOemNumber, specialCommand, oemParameter,
377 bootOptions, specialCommandParameters))
388 request.Command = rci__RemoteControlCommandType__16;
391 request.Command = rci__RemoteControlCommandType__17;
394 request.Command = rci__RemoteControlCommandType__18;
396 case PowerCycleReset:
397 request.Command = rci__RemoteControlCommandType__19;
400 request.Command = rci__RemoteControlCommandType__33;
406 if(specialCommand == NULL)
408 request.SpecialCommand = NULL;
412 request.SpecialCommand = new rci__SpecialCommandType;
413 switch(*specialCommand)
416 *(request.SpecialCommand) = rci__SpecialCommandType__0;
419 *(request.SpecialCommand) = rci__SpecialCommandType__1;
421 case ForceHardDriveBoot:
422 *(request.SpecialCommand) = rci__SpecialCommandType__2;
424 case ForceHardDriveSafeModeBoot:
425 *(request.SpecialCommand) = rci__SpecialCommandType__3;
427 case ForceDiagnosticsBoot:
428 *(request.SpecialCommand) = rci__SpecialCommandType__4;
430 case ForceCdOrDvdBoot:
431 *(request.SpecialCommand) = rci__SpecialCommandType__5;
433 case IntelOemCommand:
434 *(request.SpecialCommand) = rci__SpecialCommandType__193;
441 request.IanaOemNumber = *ianaOemNumber;
442 request.BootOptions = bootOptions;
443 request.OEMparameters = oemParameter;
444 request.SpecialCommandParameter = specialCommandParameters;
446 FunctionCall("RemoteControl");
447 res = soap_call___rci__RemoteControl(server->GetSoap(),
448 server->GetIp(),NULL, &request, &response);
450 if((status = CheckReturnStatus(res,response.Status,"RemoteControl")) == true)
455 if(request.SpecialCommand != NULL)
457 delete request.SpecialCommand;
458 request.SpecialCommand = NULL;
462 // cleanup heap allocated memory
468 if(ianaOemNumber != NULL)
470 delete ianaOemNumber;
471 ianaOemNumber = NULL;
473 if(specialCommand != NULL)
475 delete specialCommand;
476 specialCommand = NULL;
478 if(oemParameter != NULL)
483 if(bootOptions != NULL)
488 if(specialCommandParameters != NULL)
490 delete specialCommandParameters;
491 specialCommandParameters = NULL;
498 * Get user's settings for the RemoteControl function
499 * Arguments & return values:
500 * command - specifies the boot or power state operation to be performed
501 * ianaOemNumber - specifies an IANA-assigned Enterprise Number
502 * specialCommand - specifies an optional modification to the boot behavior
503 * OemParameter - specifies IntelĀ® AMT proprietary boot options
504 * bootOptions - specifies standard boot options
505 * specialCommandParameters - specifies an optional modification to the
511 bool GetUserValues(uint8 *&command, uint32 *&ianaOemNumber,
512 uint8 *&specialCommand, uint16 *&oemParameter,
513 uint16 *&bootOptions, uint16 *&specialCommandParameters)
517 printf("Please specify the following parameters\n");
519 // Get mandatory parameters
522 printf("\n\tCommand");
523 printf("\n\t=======");
524 printf("\nPossible values:");
525 printf("\n\t%u (Reset)",Reset);
526 printf("\n\t%u (PowerUp)",PowerUp);
527 printf("\n\t%u (PowerDown)",PowerDown);
528 printf("\n\t%u (PowerCycleReset)",PowerCycleReset);
529 printf("\n\t%u (SetBootOptions)\n>",SetBootOptions);
532 // verify command value
536 tmp == PowerCycleReset ||
537 tmp == SetBootOptions)
540 if ( command == NULL )
542 command = new uint8();
544 *command = (uint8)tmp;
551 // If command is Set Boot Options, ianaOemNumber
552 // should be IntelIanaNumber.
553 if( *command == SetBootOptions )
556 if ( ianaOemNumber == NULL )
558 ianaOemNumber = new uint32();
561 printf("\nSetBootOptions command selected. ");
562 printf("Iana OEM Number is IntelIanaNumber (%u)\n",IntelIanaNumber);
564 *ianaOemNumber = (uint32)IntelIanaNumber;
570 printf("\n\tIana OEM Number");
571 printf("\n\t===============");
572 printf("\nPossible values:");
573 printf("\n\t%u (IntelIanaNumber)", IntelIanaNumber);
574 printf("\n\t%u (ASFIanaNumber)\n>", ASFIanaNumber);
577 // verify ianaOemNumber value
578 if ( tmp == IntelIanaNumber ||
579 tmp == ASFIanaNumber )
582 if ( ianaOemNumber == NULL )
584 ianaOemNumber = new uint32();
586 *ianaOemNumber = (uint32)tmp;
594 // if power down, all other parameters should not be sent.
595 if ( *command == PowerDown )
597 specialCommand = NULL;
600 specialCommandParameters = NULL;
604 // Get optional parameters
606 // Get Special Command
607 printf("\n\tSpecial Command");
608 printf("\n\t===============");
609 printf("\nPossible values:");
611 printf("\n\t%d (No Special Command)",-1);
612 printf("\n\t%u (NOP)",NOP);
613 printf("\n\t%u (ForcePxeBoot)",ForcePxeBoot);
614 printf("\n\t%u (ForceHardDriveBoot)",ForceHardDriveBoot);
615 printf("\n\t%u (ForceHardDriveSafeModeBoot)",ForceHardDriveSafeModeBoot);
616 printf("\n\t%u (ForceDiagnosticsBoot)",ForceDiagnosticsBoot);
617 printf("\n\t%u (ForceCdOrDvdBoot)",ForceCdOrDvdBoot);
618 printf("\n\t%u (IntelOemCommand)\n>",IntelOemCommand);
621 // verify specialCommand value
622 if ( tmp == NO_VALUE ||
624 tmp == ForcePxeBoot ||
625 tmp == ForceHardDriveBoot ||
626 tmp == ForceHardDriveSafeModeBoot ||
627 tmp == ForceDiagnosticsBoot ||
628 tmp == ForceCdOrDvdBoot ||
629 tmp == IntelOemCommand )
631 if ( tmp == NO_VALUE )
633 specialCommand = NULL;
635 else if(tmp == IntelOemCommand &&
636 *ianaOemNumber != IntelIanaNumber)
638 printf("Error: Special Command value %d is legal", IntelOemCommand);
639 printf(" only for IanaOemNumber value %d", IntelIanaNumber);
645 if ( specialCommand == NULL )
647 specialCommand = new uint8();
649 *specialCommand = (uint8)tmp;
658 // if ianaOemNumber is ASFIanaNumber, oemParameters should not be sent .
659 if ( *ianaOemNumber != IntelIanaNumber )
665 printf("\n\tOEM Parameters");
666 printf("\n\t==============");
667 printf("\nPossible values:");
668 printf("\n\t%d (No OEM Parameters)",-1);
669 printf("\n\t%d (Undefined OEM Parameter)",UndefinedOEMParameter);
670 printf("\n\t%u (UseSol)\n>",UseSol);
672 if ( tmp == NO_VALUE )
679 if ( oemParameter == NULL )
681 oemParameter = new uint16();
683 *oemParameter = (uint16) tmp;
687 // Get Special Command Parameters
688 printf("\n\tSpecial Command Parameters");
689 printf("\n\t==========================");
690 printf("\nPossible values:");
692 // Special Command is not equal to 0xC1 (IntelOemCommand)
693 if ( specialCommand == NULL ||
694 (specialCommand != NULL) && (*specialCommand != IntelOemCommand) )
696 printf("\n\tSpecial command not equal to %d",IntelOemCommand);
697 printf("\n\tSee ASF specification for the Special Command Parameter legal values");
698 printf("\n\n\t%d (No Special Command Parameter)\n>",-1);
701 // Special Command is 0xC1, hence Special Command Parameter
702 // used to augment the Special Command
705 printf("\n\t%d (No Special Command Parameter)",-1);
706 printf("\n\t%d (Undefined Special Command Parameter)",
707 UndefinedSpecialCommandParameter);
708 printf("\n\t%u (UseIderFloppy)",UseIderFloppy);
709 printf("\n\t%u (ReflashBios)",ReflashBios);
710 printf("\n\t%u (BiosSetup)",BiosSetup);
711 printf("\n\t%u (BiosPause)",BiosPause);
712 printf("\n\t%u (UseIderCD)\n",UseIderCD);
714 printf("\nYou can choose several options by using bitwise OR operation\n\n>");
717 // verify specialCommandParameters value
718 if ( (tmp != NO_VALUE) && (tmp & SpecialCommandParametersReservedBits) )
724 if ( tmp == NO_VALUE )
726 specialCommandParameters = NULL;
731 if ( specialCommandParameters == NULL )
733 specialCommandParameters = new uint16();
735 *specialCommandParameters = (uint16)tmp;
741 printf("\n\tBoot Options");
742 printf("\n\t============");
743 printf("\nPossible values:");
745 printf("\n\t%d (No boot options)", -1);
746 printf("\n\t%u (LockPowerButton)",LockPowerButton);
747 printf("\n\t%u (LockResetButton)",LockResetButton);
748 printf("\n\t%u (LockKeyboard)",LockKeyboard);
749 printf("\n\t%u (LockSleepButton)",LockSleepButton);
750 printf("\n\t%u (UserPasswordBypass)",UserPasswordBypass);
751 printf("\n\t%u (ForceProgressEvents)",ForceProgressEvents);
753 printf("\n\n\tFirmware Verbosity Options:");
754 printf( "\n\t---------------------------");
755 printf("\n\t%u (FirmwareVerbositySystemDefault)",FirmwareVerbositySystemDefault);
756 printf("\n\t%u (FirmwareVerbosityQuiet)",FirmwareVerbosityQuiet);
757 printf("\n\t%u (FirmwareVerbosityVerbose)",FirmwareVerbosityVerbose);
758 printf("\n\t%u (FirmwareVerbosityScreen)",FirmwareVerbosityScreen);
759 printf("\n\n\t%u (ConfigurationDataReset)\n",ConfigurationDataReset);
761 printf("\nYou can choose several options by using bitwise OR operation\n\n>");
764 // verify bootOptions value
765 if ( (tmp != NO_VALUE) && (tmp & BootOptionsReservedBits) )
771 if ( tmp == NO_VALUE )
778 if ( bootOptions == NULL )
780 bootOptions = new uint16();
782 *bootOptions = (uint16)tmp;
788 printf("Error: %u is an illegal value. Aborting.\n", tmp);
793 * Prints system capabilities supported by the Intel(R) AMT device
795 * systemCapabilitiesSupported - set of flags that indicate the values
796 * the Intel(R) AMT device supports in the
797 * Command parameter of the RemoteControl method
799 void DisplaySystemCapabilities(uint8 systemCapabilitiesSupported)
801 printf("\nSystemCapabilitiesSupported = %u", systemCapabilitiesSupported);
803 if ( systemCapabilitiesSupported & SuppPowerCycleReset )
805 printf("\nPowerCycleReset ");
807 if ( systemCapabilitiesSupported & SuppPowerDown )
809 printf("\nPowerDown ");
811 if ( systemCapabilitiesSupported & SuppPowerUp )
813 printf("\nPowerUp ");
815 if ( systemCapabilitiesSupported & SuppReset )
822 * Prints special commands supported by the Intel(R) AMT device
824 * specialCommandsSupported - set of flags that indicate the values
825 * the Intel(R) AMT device supports in the
826 * SpecialCommand parameter of the
827 * RemoteControl method
829 void DisplaySpecialCommand(uint16 specialCommandsSupported)
831 printf("\nSpecialCommandsSupported = %u", specialCommandsSupported);
833 if ( specialCommandsSupported & SuppForcePXEBoot )
835 printf("\nForcePXEBoot ");
837 if ( specialCommandsSupported & SuppForceHardDriveBoot )
839 printf("\nForceHardDriveBoot ");
841 if ( specialCommandsSupported & SuppForceHardDriveSafeModeBoot )
843 printf("\nForceHardDriveSafeModeBoot ");
845 if ( specialCommandsSupported & SuppForceDiagnosticBoot )
847 printf("\nForceDiagnosticBoot ");
849 if ( specialCommandsSupported & SuppForceCDorDVDBoot )
851 printf("\nForceCDorDVDBoot");
857 * Prints firmware capabilities supported by the Intel(R) AMT device
859 * systemCapabilitiesSupported - set of flags that indicate the values
860 * the Intel(R) AMT device supports in the
861 * BootOptions parameter of the RemoteControl
864 void DisplaySystemFirmwareCapabilities(uint32 systemFirmwareCapabilities)
866 printf("\nSystemFirmwareCapabilities = %u", systemFirmwareCapabilities);
868 if ( systemFirmwareCapabilities & SuppVerbosityScreenBlank )
870 printf("\nVerbosityScreenBlank ");
872 if ( systemFirmwareCapabilities & SuppPowerButtonLock )
874 printf("\nPowerButtonLock ");
876 if ( systemFirmwareCapabilities & SuppResetButtonLock )
878 printf("\nResetButtonLock ");
880 if ( systemFirmwareCapabilities & SuppKeyboardLock )
882 printf("\nKeyboardLock ");
884 if ( systemFirmwareCapabilities & SuppSleepButtonLock )
886 printf("\nSleepButtonLock ");
888 if ( systemFirmwareCapabilities & SuppUserPasswordBypass )
890 printf("\nUserPasswordBypass ");
892 if ( systemFirmwareCapabilities & SuppForcedProgressEvents )
894 printf("\nForcedProgressEvents ");
896 if ( systemFirmwareCapabilities & SuppVerbosityVerbose )
898 printf("\nVerbosityVerbose ");
900 if ( systemFirmwareCapabilities & SuppVerbosityQuiet )
902 printf("\nVerbosityQuiet ");
904 if ( systemFirmwareCapabilities & SuppConfigurationDataReset )
906 printf("\nConfigurationDataReset");
912 * Prints OEM defined capabilities supported by the Intel(R) AMT device
914 * systemCapabilitiesSupported - set of flags that indicate the values
915 * the Intel(R) AMT device supports in the
916 * OemParameters parameter of the RemoteControl
919 void DisplayOemDefinedCapabilities(uint32 oemDefinedCapabilities)
921 printf("\nOemDefinedCapabilities = %u", oemDefinedCapabilities);
923 if ( oemDefinedCapabilities & SuppIDER )
927 if ( oemDefinedCapabilities & SuppSOL )
931 if ( oemDefinedCapabilities & SuppBiosReflash )
933 printf("\nBiosReflash");
935 if ( oemDefinedCapabilities & SuppBiosSetup )
937 printf("\nBiosSetup");
939 if ( oemDefinedCapabilities & SuppBiosPause )
941 printf("\nBiosPause");