blob: d5eab0795c2256ae11a9ded1987edaa7542e90b8 [file] [log] [blame]
Ed Tanous4758d5b2017-06-06 15:28:13 -07001angular.module('bmcApp').controller('fwupdateController', [
Ed Tanous3dac7492017-08-02 13:46:20 -07002 '$scope', '$http', '$uibModal', '$state',
Ed Tanous4758d5b2017-06-06 15:28:13 -07003 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);
Ed Tanous3dac7492017-08-02 13:46:20 -070051 $http({
52 method : 'POST',
53 url : '/intel/firmwareupload',
54 data : e.target.result,
55 transformRequest : [],
56 headers : {'Content-Type' : 'application/octet-stream'}
57 })
Ed Tanous4758d5b2017-06-06 15:28:13 -070058 .then(
59 function successCallback(response) {
60 console.log('Success uploaded. Response: ' +
61 response.data)
62 },
63 function errorCallback(response) {
64 console.log('Error status: ' + response.status)
65 });
66 };
67
68 // The function that is called for modal dismissal(negative button)
69
70 $scope.dismissModal = function() {
71 objectSelectionModal.dismiss();
72 };
73
74 }
75
76 });
77 };
78 var file_to_load = files[0];
79 $scope.file_to_load = file_to_load;
80 r.readAsArrayBuffer(files[0]);
81
82 };
83
84 $scope.filename = '';
85 }
86]);