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);
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 if ((status = ExecuteRemoteControl(server,true)) == false)
181 case OPT_REDUCED_API_TEST:
182 if((status = ExecuteGetSystemPowerstate(server,verbose)) == false)
186 if((status = ExecuteGetRemoteControlCapabilities(server,verbose)) == false)
199 * Prints a usage information for the user.
201 void Usage(char *cmd)
205 printf("\t %s <opt> [%s] [%s <name> %s <pass>] http[s]:", cmd, VERBOSE, CERT_NAME, CERT_PASS);
207 printf("\t %s <opt> [%s] [%s <username> %s <password>] [%s <name>] http[s]:",
208 cmd, VERBOSE, USER, PASS, CERT_NAME);
210 printf("//<Hostname>:<Port>/<RemoteControlUri> ");
212 printf("[%s <username> %s <password>]\n",USER,PASS);
214 printf("\nWhere <opt> is :\n");
215 printf("\t %s : GetSystemPowerstate\n",POWER);
216 printf("\t %s : GetRemoteControlCapabilities\n",CAPABILITIES);
217 printf("\t %s : RemoteControl\n",REMOTE);
218 printf("\t %s : perform API test\n",API_TEST);
219 printf("\t %s : perform API test without boot\n",REDUCED_API_TEST);
220 printf("\t To run API test in verbose mode include %s option\n", VERBOSE);
221 PrintAuthenticationNote();
222 printf("\nExample:\n");
223 printf("\t %s %s ", cmd, POWER);
224 printf("http://hostname:16992/RemoteControlService\n");
226 printf("\t %s %s %s MyCert %s Pass https://hostname:16993/RemoteControlService\n",
227 cmd, POWER, CERT_NAME, CERT_PASS);
229 printf("\t %s %s %s MyCert https://hostname:16993/RemoteControlService\n",
230 cmd, POWER, CERT_NAME);
235 * Queries (using SOAP) and display the system power state
237 * server - pointer to the runtime environment
238 * url - address of the web service
239 * verbose - boolean value for API test
244 bool ExecuteGetSystemPowerstate(Soap* server, bool verbose)
251 // gSOAP structures for handling
252 // request and response information
253 _rci__GetSystemPowerState request;
254 _rci__GetSystemPowerStateResponse response;
256 FunctionCall("GetSystemPowerState");
257 res = soap_call___rci__GetSystemPowerState(server->GetSoap(),
258 server->GetIp(),NULL, &request, &response);
261 CheckReturnStatus(res,
263 "GetSystemPowerState")) == true)
267 printf("\nSystemPowerstate is: %u\n", response.SystemPowerState);
279 * Queries (using SOAP) and display the Intel(R) AMT
280 * device remote control capabilities
282 * server - pointer to the runtime environment
283 * url - address of the web service
284 * verbose - boolean value for API test
289 bool ExecuteGetRemoteControlCapabilities(Soap* server, bool verbose)
296 // gSOAP structures for handling
297 // request and response information
298 _rci__GetRemoteControlCapabilities request;
299 _rci__GetRemoteControlCapabilitiesResponse response;
301 FunctionCall("GetRemoteControlCapabilities");
302 res = soap_call___rci__GetRemoteControlCapabilities(server->GetSoap(),
303 server->GetIp(),NULL, &request, &response);
305 if((status = CheckReturnStatus(res,response.Status,"GetRemoteControlCapabilities")) == true)
309 printf("\nRemote Control Capabilities\n");
310 printf("---------------------------------------\n");
312 printf("IanaOemNumber = %u\n", response.IanaOemNumber);
314 DisplayOemDefinedCapabilities(response.OemDefinedCapabilities);
317 DisplaySpecialCommand(response.SpecialCommandsSupported);
320 DisplaySystemCapabilities(response.SystemCapabilitiesSupported);
323 DisplaySystemFirmwareCapabilities(response.SystemFirmwareCapabilities);
337 * Controls remotely (using SOAP) the boot and power state of
338 * Intel(R) AMT-managed PC.
340 * server - pointer to the runtime environment
341 * url - address of the web service
342 * def_values - if false request values from user
347 bool ExecuteRemoteControl(Soap* server,bool def_values)
354 // gSOAP structures for handling
355 // request and response information
356 _rci__RemoteControl request;
357 _rci__RemoteControlResponse response;
360 uint8 *command = new uint8(Reset);
361 uint32 *ianaOemNumber = new uint32(IntelIanaNumber);
362 uint8 *specialCommand = NULL; //none
363 uint16 *oemParameter = NULL; //none
364 uint16 *bootOptions = NULL; //none
365 uint16 *specialCommandParameters = NULL; //none
369 // To use default values above, comment the following line.
370 if(!GetUserValues(command, ianaOemNumber, specialCommand, oemParameter,
371 bootOptions, specialCommandParameters))
382 request.Command = rci__RemoteControlCommandType__16;
385 request.Command = rci__RemoteControlCommandType__17;
388 request.Command = rci__RemoteControlCommandType__18;
390 case PowerCycleReset:
391 request.Command = rci__RemoteControlCommandType__19;
394 request.Command = rci__RemoteControlCommandType__33;
400 if(specialCommand == NULL)
402 request.SpecialCommand = NULL;
406 request.SpecialCommand = new rci__SpecialCommandType;
407 switch(*specialCommand)
410 *(request.SpecialCommand) = rci__SpecialCommandType__0;
413 *(request.SpecialCommand) = rci__SpecialCommandType__1;
415 case ForceHardDriveBoot:
416 *(request.SpecialCommand) = rci__SpecialCommandType__2;
418 case ForceHardDriveSafeModeBoot:
419 *(request.SpecialCommand) = rci__SpecialCommandType__3;
421 case ForceDiagnosticsBoot:
422 *(request.SpecialCommand) = rci__SpecialCommandType__4;
424 case ForceCdOrDvdBoot:
425 *(request.SpecialCommand) = rci__SpecialCommandType__5;
427 case IntelOemCommand:
428 *(request.SpecialCommand) = rci__SpecialCommandType__193;
435 request.IanaOemNumber = *ianaOemNumber;
436 request.BootOptions = bootOptions;
437 request.OEMparameters = oemParameter;
438 request.SpecialCommandParameter = specialCommandParameters;
440 FunctionCall("RemoteControl");
441 res = soap_call___rci__RemoteControl(server->GetSoap(),
442 server->GetIp(),NULL, &request, &response);
444 if((status = CheckReturnStatus(res,response.Status,"RemoteControl")) == true)
449 if(request.SpecialCommand != NULL)
451 delete request.SpecialCommand;
452 request.SpecialCommand = NULL;
456 // cleanup heap allocated memory
462 if(ianaOemNumber != NULL)
464 delete ianaOemNumber;
465 ianaOemNumber = NULL;
467 if(specialCommand != NULL)
469 delete specialCommand;
470 specialCommand = NULL;
472 if(oemParameter != NULL)
477 if(bootOptions != NULL)
482 if(specialCommandParameters != NULL)
484 delete specialCommandParameters;
485 specialCommandParameters = NULL;
492 * Get user's settings for the RemoteControl function
493 * Arguments & return values:
494 * command - specifies the boot or power state operation to be performed
495 * ianaOemNumber - specifies an IANA-assigned Enterprise Number
496 * specialCommand - specifies an optional modification to the boot behavior
497 * OemParameter - specifies IntelĀ® AMT proprietary boot options
498 * bootOptions - specifies standard boot options
499 * specialCommandParameters - specifies an optional modification to the
505 bool GetUserValues(uint8 *&command, uint32 *&ianaOemNumber,
506 uint8 *&specialCommand, uint16 *&oemParameter,
507 uint16 *&bootOptions, uint16 *&specialCommandParameters)
511 printf("Please specify the following parameters\n");
513 // Get mandatory parameters
516 printf("\n\tCommand");
517 printf("\n\t=======");
518 printf("\nPossible values:");
519 printf("\n\t%u (Reset)",Reset);
520 printf("\n\t%u (PowerUp)",PowerUp);
521 printf("\n\t%u (PowerDown)",PowerDown);
522 printf("\n\t%u (PowerCycleReset)",PowerCycleReset);
523 printf("\n\t%u (SetBootOptions)\n>",SetBootOptions);
526 // verify command value
530 tmp == PowerCycleReset ||
531 tmp == SetBootOptions)
534 if ( command == NULL )
536 command = new uint8();
538 *command = (uint8)tmp;
545 // If command is Set Boot Options, ianaOemNumber
546 // should be IntelIanaNumber.
547 if( *command == SetBootOptions )
550 if ( ianaOemNumber == NULL )
552 ianaOemNumber = new uint32();
555 printf("\nSetBootOptions command selected. ");
556 printf("Iana OEM Number is IntelIanaNumber (%u)\n",IntelIanaNumber);
558 *ianaOemNumber = (uint32)IntelIanaNumber;
564 printf("\n\tIana OEM Number");
565 printf("\n\t===============");
566 printf("\nPossible values:");
567 printf("\n\t%u (IntelIanaNumber)", IntelIanaNumber);
568 printf("\n\t%u (ASFIanaNumber)\n>", ASFIanaNumber);
571 // verify ianaOemNumber value
572 if ( tmp == IntelIanaNumber ||
573 tmp == ASFIanaNumber )
576 if ( ianaOemNumber == NULL )
578 ianaOemNumber = new uint32();
580 *ianaOemNumber = (uint32)tmp;
588 // if power down, all other parameters should not be sent.
589 if ( *command == PowerDown )
591 specialCommand = NULL;
594 specialCommandParameters = NULL;
598 // Get optional parameters
600 // Get Special Command
601 printf("\n\tSpecial Command");
602 printf("\n\t===============");
603 printf("\nPossible values:");
605 printf("\n\t%d (No Special Command)",-1);
606 printf("\n\t%u (NOP)",NOP);
607 printf("\n\t%u (ForcePxeBoot)",ForcePxeBoot);
608 printf("\n\t%u (ForceHardDriveBoot)",ForceHardDriveBoot);
609 printf("\n\t%u (ForceHardDriveSafeModeBoot)",ForceHardDriveSafeModeBoot);
610 printf("\n\t%u (ForceDiagnosticsBoot)",ForceDiagnosticsBoot);
611 printf("\n\t%u (ForceCdOrDvdBoot)",ForceCdOrDvdBoot);
612 printf("\n\t%u (IntelOemCommand)\n>",IntelOemCommand);
615 // verify specialCommand value
616 if ( tmp == NO_VALUE ||
618 tmp == ForcePxeBoot ||
619 tmp == ForceHardDriveBoot ||
620 tmp == ForceHardDriveSafeModeBoot ||
621 tmp == ForceDiagnosticsBoot ||
622 tmp == ForceCdOrDvdBoot ||
623 tmp == IntelOemCommand )
625 if ( tmp == NO_VALUE )
627 specialCommand = NULL;
629 else if(tmp == IntelOemCommand &&
630 *ianaOemNumber != IntelIanaNumber)
632 printf("Error: Special Command value %d is legal", IntelOemCommand);
633 printf(" only for IanaOemNumber value %d", IntelIanaNumber);
639 if ( specialCommand == NULL )
641 specialCommand = new uint8();
643 *specialCommand = (uint8)tmp;
652 // if ianaOemNumber is ASFIanaNumber, oemParameters should not be sent .
653 if ( *ianaOemNumber != IntelIanaNumber )
659 printf("\n\tOEM Parameters");
660 printf("\n\t==============");
661 printf("\nPossible values:");
662 printf("\n\t%d (No OEM Parameters)",-1);
663 printf("\n\t%d (Undefined OEM Parameter)",UndefinedOEMParameter);
664 printf("\n\t%u (UseSol)\n>",UseSol);
666 if ( tmp == NO_VALUE )
673 if ( oemParameter == NULL )
675 oemParameter = new uint16();
677 *oemParameter = (uint16) tmp;
681 // Get Special Command Parameters
682 printf("\n\tSpecial Command Parameters");
683 printf("\n\t==========================");
684 printf("\nPossible values:");
686 // Special Command is not equal to 0xC1 (IntelOemCommand)
687 if ( specialCommand == NULL ||
688 (specialCommand != NULL) && (*specialCommand != IntelOemCommand) )
690 printf("\n\tSpecial command not equal to %d",IntelOemCommand);
691 printf("\n\tSee ASF specification for the Special Command Parameter legal values");
692 printf("\n\n\t%d (No Special Command Parameter)\n>",-1);
695 // Special Command is 0xC1, hence Special Command Parameter
696 // used to augment the Special Command
699 printf("\n\t%d (No Special Command Parameter)",-1);
700 printf("\n\t%d (Undefined Special Command Parameter)",
701 UndefinedSpecialCommandParameter);
702 printf("\n\t%u (UseIderFloppy)",UseIderFloppy);
703 printf("\n\t%u (ReflashBios)",ReflashBios);
704 printf("\n\t%u (BiosSetup)",BiosSetup);
705 printf("\n\t%u (BiosPause)",BiosPause);
706 printf("\n\t%u (UseIderCD)\n",UseIderCD);
708 printf("\nYou can choose several options by using bitwise OR operation\n\n>");
711 // verify specialCommandParameters value
712 if ( (tmp != NO_VALUE) && (tmp & SpecialCommandParametersReservedBits) )
718 if ( tmp == NO_VALUE )
720 specialCommandParameters = NULL;
725 if ( specialCommandParameters == NULL )
727 specialCommandParameters = new uint16();
729 *specialCommandParameters = (uint16)tmp;
735 printf("\n\tBoot Options");
736 printf("\n\t============");
737 printf("\nPossible values:");
739 printf("\n\t%d (No boot options)", -1);
740 printf("\n\t%u (LockPowerButton)",LockPowerButton);
741 printf("\n\t%u (LockResetButton)",LockResetButton);
742 printf("\n\t%u (LockKeyboard)",LockKeyboard);
743 printf("\n\t%u (LockSleepButton)",LockSleepButton);
744 printf("\n\t%u (UserPasswordBypass)",UserPasswordBypass);
745 printf("\n\t%u (ForceProgressEvents)",ForceProgressEvents);
747 printf("\n\n\tFirmware Verbosity Options:");
748 printf( "\n\t---------------------------");
749 printf("\n\t%u (FirmwareVerbositySystemDefault)",FirmwareVerbositySystemDefault);
750 printf("\n\t%u (FirmwareVerbosityQuiet)",FirmwareVerbosityQuiet);
751 printf("\n\t%u (FirmwareVerbosityVerbose)",FirmwareVerbosityVerbose);
752 printf("\n\t%u (FirmwareVerbosityScreen)",FirmwareVerbosityScreen);
753 printf("\n\n\t%u (ConfigurationDataReset)\n",ConfigurationDataReset);
755 printf("\nYou can choose several options by using bitwise OR operation\n\n>");
758 // verify bootOptions value
759 if ( (tmp != NO_VALUE) && (tmp & BootOptionsReservedBits) )
765 if ( tmp == NO_VALUE )
772 if ( bootOptions == NULL )
774 bootOptions = new uint16();
776 *bootOptions = (uint16)tmp;
782 printf("Error: %u is an illegal value. Aborting.\n", tmp);
787 * Prints system capabilities supported by the Intel(R) AMT device
789 * systemCapabilitiesSupported - set of flags that indicate the values
790 * the Intel(R) AMT device supports in the
791 * Command parameter of the RemoteControl method
793 void DisplaySystemCapabilities(uint8 systemCapabilitiesSupported)
795 printf("\nSystemCapabilitiesSupported = %u", systemCapabilitiesSupported);
797 if ( systemCapabilitiesSupported & SuppPowerCycleReset )
799 printf("\nPowerCycleReset ");
801 if ( systemCapabilitiesSupported & SuppPowerDown )
803 printf("\nPowerDown ");
805 if ( systemCapabilitiesSupported & SuppPowerUp )
807 printf("\nPowerUp ");
809 if ( systemCapabilitiesSupported & SuppReset )
816 * Prints special commands supported by the Intel(R) AMT device
818 * specialCommandsSupported - set of flags that indicate the values
819 * the Intel(R) AMT device supports in the
820 * SpecialCommand parameter of the
821 * RemoteControl method
823 void DisplaySpecialCommand(uint16 specialCommandsSupported)
825 printf("\nSpecialCommandsSupported = %u", specialCommandsSupported);
827 if ( specialCommandsSupported & SuppForcePXEBoot )
829 printf("\nForcePXEBoot ");
831 if ( specialCommandsSupported & SuppForceHardDriveBoot )
833 printf("\nForceHardDriveBoot ");
835 if ( specialCommandsSupported & SuppForceHardDriveSafeModeBoot )
837 printf("\nForceHardDriveSafeModeBoot ");
839 if ( specialCommandsSupported & SuppForceDiagnosticBoot )
841 printf("\nForceDiagnosticBoot ");
843 if ( specialCommandsSupported & SuppForceCDorDVDBoot )
845 printf("\nForceCDorDVDBoot");
851 * Prints firmware capabilities supported by the Intel(R) AMT device
853 * systemCapabilitiesSupported - set of flags that indicate the values
854 * the Intel(R) AMT device supports in the
855 * BootOptions parameter of the RemoteControl
858 void DisplaySystemFirmwareCapabilities(uint32 systemFirmwareCapabilities)
860 printf("\nSystemFirmwareCapabilities = %u", systemFirmwareCapabilities);
862 if ( systemFirmwareCapabilities & SuppVerbosityScreenBlank )
864 printf("\nVerbosityScreenBlank ");
866 if ( systemFirmwareCapabilities & SuppPowerButtonLock )
868 printf("\nPowerButtonLock ");
870 if ( systemFirmwareCapabilities & SuppResetButtonLock )
872 printf("\nResetButtonLock ");
874 if ( systemFirmwareCapabilities & SuppKeyboardLock )
876 printf("\nKeyboardLock ");
878 if ( systemFirmwareCapabilities & SuppSleepButtonLock )
880 printf("\nSleepButtonLock ");
882 if ( systemFirmwareCapabilities & SuppUserPasswordBypass )
884 printf("\nUserPasswordBypass ");
886 if ( systemFirmwareCapabilities & SuppForcedProgressEvents )
888 printf("\nForcedProgressEvents ");
890 if ( systemFirmwareCapabilities & SuppVerbosityVerbose )
892 printf("\nVerbosityVerbose ");
894 if ( systemFirmwareCapabilities & SuppVerbosityQuiet )
896 printf("\nVerbosityQuiet ");
898 if ( systemFirmwareCapabilities & SuppConfigurationDataReset )
900 printf("\nConfigurationDataReset");
906 * Prints OEM defined capabilities supported by the Intel(R) AMT device
908 * systemCapabilitiesSupported - set of flags that indicate the values
909 * the Intel(R) AMT device supports in the
910 * OemParameters parameter of the RemoteControl
913 void DisplayOemDefinedCapabilities(uint32 oemDefinedCapabilities)
915 printf("\nOemDefinedCapabilities = %u", oemDefinedCapabilities);
917 if ( oemDefinedCapabilities & SuppIDER )
921 if ( oemDefinedCapabilities & SuppSOL )
925 if ( oemDefinedCapabilities & SuppBiosReflash )
927 printf("\nBiosReflash");
929 if ( oemDefinedCapabilities & SuppBiosSetup )
931 printf("\nBiosSetup");
933 if ( oemDefinedCapabilities & SuppBiosPause )
935 printf("\nBiosPause");