blob: ceacd8a43c7c55b5b94c8a4046703c767083e965 [file] [log] [blame]
angular.module('bmcApp').controller('fwupdateController', [
'$scope', '$http', '$uibModal',
function($scope, $http, $uibModal, $state) {
$scope.upload = function(files) {
r = new FileReader();
r.onload = function(e) {
get_image_info = function(buffer) {
image_info = {'valid' : false}
var expected = '*SignedImage*\0\0\0'
var dv1 = new Int8Array(e.target.result, 0, 16);
for (var i = 0; i != expected.length; i++) {
if (dv1[i] != expected.charCodeAt(i)) {
return image_info;
}
}
image_info['valid'] = true;
var generation = new Int8Array(e.target.result, 16, 17)[0];
image_info['generation'] = generation;
if ((generation < 4) ||
(generation > 5)) { // not VLN generation header
return image_info;
} else {
var version_minor = new Uint16Array(e.target.result, 20, 22)[0];
image_info['major_version'] =
new Uint8Array(e.target.result, 28, 29)[0];
image_info['submajor_version'] =
new Uint8Array(e.target.result, 29, 30)[0].toString(16);
var version_minor2 = new Uint16Array(e.target.result, 30, 32)[0];
image_info['sha1_version'] =
('0000' + version_minor2.toString(16)).substr(-4) +
('0000' + version_minor.toString(16)).substr(-4);
}
return image_info;
};
var image_info = get_image_info(e.target.result);
$scope.image_info = image_info;
var objectSelectionModal = $uibModal.open({
templateUrl : 'static/partial-fwupdateconfirm.html',
controller : function($scope) {
$scope.image_info = image_info;
$scope.file_to_load = file_to_load;
// The function that is called for modal closing (positive button)
$scope.okModal = function() {
// Closing the model with result
objectSelectionModal.close($scope.selection);
$http
.post(
'/intel/firmwareupload', data = e.target.result,
{headers : {'Content-Type' : 'application/octet-stream'}})
.then(
function successCallback(response) {
console.log('Success uploaded. Response: ' +
response.data)
},
function errorCallback(response) {
console.log('Error status: ' + response.status)
});
};
// The function that is called for modal dismissal(negative button)
$scope.dismissModal = function() {
objectSelectionModal.dismiss();
};
}
});
};
var file_to_load = files[0];
$scope.file_to_load = file_to_load;
r.readAsArrayBuffer(files[0]);
};
$scope.filename = '';
}
]);