blob: ceacd8a43c7c55b5b94c8a4046703c767083e965 [file] [log] [blame]
Ed Tanous4758d5b2017-06-06 15:28:13 -07001angular.module('bmcApp').controller('fwupdateController', [
2 '$scope', '$http', '$uibModal',
3 function($scope, $http, $uibModal, $state) {
4 $scope.upload = function(files) {
5 r = new FileReader();
6 r.onload = function(e) {
7 get_image_info = function(buffer) {
8 image_info = {'valid' : false}
9 var expected = '*SignedImage*\0\0\0'
10
11 var dv1 = new Int8Array(e.target.result, 0, 16);
12
13 for (var i = 0; i != expected.length; i++) {
14 if (dv1[i] != expected.charCodeAt(i)) {
15 return image_info;
16 }
17 }
18 image_info['valid'] = true;
19 var generation = new Int8Array(e.target.result, 16, 17)[0];
20 image_info['generation'] = generation;
21 if ((generation < 4) ||
22 (generation > 5)) { // not VLN generation header
23
24 return image_info;
25 } else {
26 var version_minor = new Uint16Array(e.target.result, 20, 22)[0];
27 image_info['major_version'] =
28 new Uint8Array(e.target.result, 28, 29)[0];
29 image_info['submajor_version'] =
30 new Uint8Array(e.target.result, 29, 30)[0].toString(16);
31 var version_minor2 = new Uint16Array(e.target.result, 30, 32)[0];
32 image_info['sha1_version'] =
33 ('0000' + version_minor2.toString(16)).substr(-4) +
34 ('0000' + version_minor.toString(16)).substr(-4);
35 }
36 return image_info;
37 };
38 var image_info = get_image_info(e.target.result);
39 $scope.image_info = image_info;
40
41 var objectSelectionModal = $uibModal.open({
42 templateUrl : 'static/partial-fwupdateconfirm.html',
43 controller : function($scope) {
44 $scope.image_info = image_info;
45 $scope.file_to_load = file_to_load;
46 // The function that is called for modal closing (positive button)
47
48 $scope.okModal = function() {
49 // Closing the model with result
50 objectSelectionModal.close($scope.selection);
51 $http
52 .post(
53 '/intel/firmwareupload', data = e.target.result,
54 {headers : {'Content-Type' : 'application/octet-stream'}})
55 .then(
56 function successCallback(response) {
57 console.log('Success uploaded. Response: ' +
58 response.data)
59 },
60 function errorCallback(response) {
61 console.log('Error status: ' + response.status)
62 });
63 };
64
65 // The function that is called for modal dismissal(negative button)
66
67 $scope.dismissModal = function() {
68 objectSelectionModal.dismiss();
69 };
70
71 }
72
73 });
74 };
75 var file_to_load = files[0];
76 $scope.file_to_load = file_to_load;
77 r.readAsArrayBuffer(files[0]);
78
79 };
80
81 $scope.filename = '';
82 }
83]);