Add MeshCMD AMTWifi setting capability

jsastriawan committed Apr 9, 2020 at 12:14 UTC e74c5a2ee5c5eea542200462a9cd903412bc5880
1 file changed +139 -1
agents/meshcmd.js
+139 -1
@@ -114,7 +114,7 @@ function run(argv) {
114 //console.log('addedModules = ' + JSON.stringify(addedModules));
115 var actionpath = 'meshaction.txt';
116 if (args.actionfile != null) { actionpath = args.actionfile; }
117 - var actions = ['HELP', 'ROUTE', 'MICROLMS', 'AMTSCAN', 'AMTPOWER', 'AMTFEATURES', 'AMTNETWORK', 'AMTLOADWEBAPP', 'AMTLOADSMALLWEBAPP', 'AMTLOADLARGEWEBAPP', 'AMTCLEARWEBAPP', 'AMTSTORAGESTATE', 'AMTINFO', 'AMTINFODEBUG', 'AMTVERSIONS', 'AMTHASHES', 'AMTSAVESTATE', 'AMTSCRIPT', 'AMTUUID', 'AMTCCM', 'AMTACM', 'AMTDEACTIVATE', 'AMTACMDEACTIVATE', 'SMBIOS', 'RAWSMBIOS', 'MESHCOMMANDER', 'AMTAUDITLOG', 'AMTEVENTLOG', 'AMTPRESENCE'];
117 + var actions = ['HELP', 'ROUTE', 'MICROLMS', 'AMTSCAN', 'AMTPOWER', 'AMTFEATURES', 'AMTNETWORK', 'AMTLOADWEBAPP', 'AMTLOADSMALLWEBAPP', 'AMTLOADLARGEWEBAPP', 'AMTCLEARWEBAPP', 'AMTSTORAGESTATE', 'AMTINFO', 'AMTINFODEBUG', 'AMTVERSIONS', 'AMTHASHES', 'AMTSAVESTATE', 'AMTSCRIPT', 'AMTUUID', 'AMTCCM', 'AMTACM', 'AMTDEACTIVATE', 'AMTACMDEACTIVATE', 'SMBIOS', 'RAWSMBIOS', 'MESHCOMMANDER', 'AMTAUDITLOG', 'AMTEVENTLOG', 'AMTPRESENCE', 'AMTWIFI'];
118
119 // Load the action file
120 var actionfile = null;
@@ -200,6 +200,7 @@ function run(argv) {
200 console.log(' AmtFeatures - Intel AMT features & user consent.');
201 console.log(' AmtNetwork - Intel AMT network interface settings.');
202 console.log(' AmtScan - Search local network for Intel AMT devices.');
203 + console.log(' AmtWifi - Intel AMT Wifi interface settings.');
204 console.log('\r\nHelp on a specific action using:\r\n');
205 console.log(' meshcmd help [action]');
206 exit(1); return;
@@ -385,6 +386,24 @@ function run(argv) {
386 console.log('AmtSCAN will look for Intel AMT device on the network. Example usage:\r\n\r\n meshcmd amtscan --scan 192.168.1.0/24');
387 console.log('\r\Required arguments:\r\n');
388 console.log(' --scan [ip range] The IP address range to perform the scan on.');
389 + } else if (action == 'amtwifi') {
390 + console.log('AmtWifi is used to get/set Intel AMT Wifi configuration. Example usage:\r\n\r\n meshcmd amtwifi --host 1.2.3.4 --user admin --pass mypassword --list');
391 + console.log('\r\nRequired arguments:\r\n');
392 + console.log(' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.');
393 + console.log(' --pass [password] The Intel AMT login password.');
394 + console.log(' --[action] Action options are list, add, del.');
395 + console.log('\r\nOptional arguments:\r\n');
396 + console.log(' --user [username] The Intel AMT login username, admin is default.');
397 + console.log(' --tls Specifies that TLS must be used.');
398 + console.log(' --list List of stored Wifi profile');
399 + console.log(' --add Add new Wifi profile');
400 + console.log(' --name New Wifi profile name');
401 + console.log(' --priority Priority of this profile - default 1');
402 + console.log(' --ssid Wifi SSID');
403 + console.log(' --auth Wifi Authentication method (4 - WPA, 6 - WPA2/RSN) - default 6');
404 + console.log(' --enc Wifi Encryption type (3 - TKIP, 4 - CCMP) - default 3');
405 + console.log(' --psk Wifi password/pre-shared key');
406 + console.log(' --del [profile-name] Delete new Wifi profile');
407 } else {
408 actions.shift();
409 console.log('Invalid action, usage:\r\n\r\n meshcmd help [action]\r\n\r\nValid actions are: ' + actions.join(', ') + '.');
@@ -690,6 +709,27 @@ function run(argv) {
709 if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
710 if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
711 performAmtNetConfig(args);
712 + } else if (settings.action == 'amtwifi') { // Perform remote Intel AMT Wifi configuration operation
713 + if (settings.hostname == null) { settings.hostname = '127.0.0.1'; }
714 + if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
715 + if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; }
716 + if (args.add != null) {
717 + if ((args.name == null) || (typeof args.name != 'string') || args.name == '') {
718 + console.log("Wifi profile name is required."); exit(1); return;
719 + }
720 + if ((args.ssid == null) || (typeof args.ssid != 'string') || args.ssid == '') {
721 + console.log("Wifi SSID is required."); exit(1); return;
722 + }
723 + if ((args.psk == null) || (typeof args.psk != 'string') || args.psk == '') {
724 + console.log("Wifi password is required."); exit(1); return;
725 + }
726 + }
727 + if (args.del !=null) {
728 + if ((settings.name == null) || (typeof settings.name != 'string') || settings.name == '') {
729 + console.log("Wifi profile name is required."); exit(1); return;
730 + }
731 + }
732 + performAmtWifiConfig(args);
733 } else if (settings.action == 'amtfeatures') { // Perform remote Intel AMT feature configuration operation
734 if (settings.hostname == null) { settings.hostname = '127.0.0.1'; }
735 if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
@@ -2472,6 +2512,104 @@ function performAmtNetConfig1(stack, name, response, status, args) {
2512 }
2513 }
2514
2515 +//
2516 +// Intel AMT Wifi configuration
2517 +//
2518 +
2519 +function performAmtWifiConfig(args) {
2520 + if ((settings.hostname == '127.0.0.1') || (settings.hostname.toLowerCase() == 'localhost')) {
2521 + settings.noconsole = true; startLms(performAmtWifiConfig0, false, args);
2522 + } else {
2523 + performAmtWifiConfig0(1, args);
2524 + }
2525 +}
2526 +
2527 +function performAmtWifiConfig0(state, args) {
2528 + var transport = require('amt-wsman-duk');
2529 + var wsman = require('amt-wsman');
2530 + var amt = require('amt');
2531 + wsstack = new wsman(transport, settings.hostname, settings.tls ? 16993 : 16992, settings.username, settings.password, settings.tls);
2532 + amtstack = new amt(wsstack);
2533 + amtstack.BatchEnum(null, ['CIM_WiFiEndpointSettings'], performAmtWifiConfig1, args);
2534 +}
2535 +
2536 +function performAmtWifiConfig1(stack, name, response, status, args) {
2537 + if ( status == 200 ) {
2538 + var wifiAuthMethod = {1: "Other", 2: "Open", 3: "Shared Key", 4: "WPA PSK", 5: "WPA 802.1x", 6: "WPA2 PSK", 7: "WPA2 802.1x", 32768 : "WPA3 802.1x"};
2539 + var wifiEncMethod = {1: "Other", 2: "WEP", 3: "TKIP", 4: "CCMP", 5: "None"}
2540 + var wifiProfiles = {};
2541 + for (var y in response['CIM_WiFiEndpointSettings'].responses) {
2542 + var z = response['CIM_WiFiEndpointSettings'].responses[y];
2543 + var n = z['ElementName'];
2544 + wifiProfiles[n]= {'Priority': z['Priority'], 'SSID':z['SSID'],'AuthenticationMethod': z['AuthenticationMethod'], 'EncryptionMethod': z['EncryptionMethod']};
2545 + }
2546 +
2547 + if (args) {
2548 + if (args.list) {
2549 + console.log('List of AMT Wifi profiles:');
2550 + if (wifiProfiles.length==0) {
2551 + console.log('No Wifi profiles is stored.');
2552 + }
2553 + for (var t in wifiProfiles) {
2554 + var w = wifiProfiles[t];
2555 + console.log('Profile Name: '+t+'; Priority: '+w['Priority']+ '; SSID: '+w['SSID']+'; Security: '+wifiAuthMethod[w['AuthenticationMethod']]+'/'+wifiEncMethod[w['EncryptionMethod']]);
2556 + }
2557 + process.exit(0);
2558 + } else if (args.add) {
2559 + if (args.auth==null) {args.auth=6}//if not set, default to WPA2 PSK
2560 + if (args.enc==null) {args.enc=3}//if not set, default to TKIP
2561 + if (args.priority==null) {args.priority=0}//if not set, default to 0
2562 +
2563 + var wifiep = {
2564 + __parameterType: 'reference',
2565 + __resourceUri: 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_WiFiEndpoint',
2566 + Name: 'WiFi Endpoint 0'
2567 + };
2568 +
2569 + var wifiepsettinginput = {
2570 + __parameterType: 'instance',
2571 + __namespace: 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_WiFiEndpointSettings',
2572 + ElementName: args.name,
2573 + InstanceID: 'Intel(r) AMT:WiFi Endpoint Settings ' + args.name,
2574 + AuthenticationMethod: args.auth,
2575 + EncryptionMethod: args.enc,
2576 + SSID: args.ssid,
2577 + Priority: args.priority,
2578 + PSKPassPhrase: args.psk
2579 + }
2580 + stack.AMT_WiFiPortConfigurationService_AddWiFiSettings(wifiep, wifiepsettinginput, null, null, null,
2581 + function(stck, nm, resp, sts) {
2582 + if (sts==200) {
2583 + console.log("Wifi profile " + args.name + " successfully added.");
2584 + } else {
2585 + console.log("Failed to add wifi profile " + args.name + ".");
2586 + }
2587 + process.exit(0);
2588 + });
2589 + } else if (args.del) {
2590 + if (wifiProfiles[args.name]==null) {
2591 + console.log("Profile "+args.name+" could not be found.");
2592 + process.exit(0);
2593 + }
2594 + stack.Delete('CIM_WiFiEndpointSettings', { InstanceID : 'Intel(r) AMT:WiFi Endpoint Settings ' + args.name },
2595 + function(stck, nm, resp, sts){
2596 + if (sts==200) {
2597 + console.log("Wifi profile " + args.name + " successfully deleted.");
2598 + } else {
2599 + console.log("Failed to delete wifi profile " + args.name + ".");
2600 + }
2601 + process.exit(0);
2602 + },
2603 + 0, 1);
2604 + }
2605 + } else {
2606 + process.exit(0);
2607 + }
2608 + } else {
2609 + console.log("Error, status " + status + ".");
2610 + process.exit(1);
2611 + }
2612 +}
2613
2614 //
2615 // Intel AMT feature configuration action