Use OUI instead of manufacturer to identify firmware files.
This commit is contained in:
1 parent
c7a2cdb448
commit
97700eb6c8
6 files changed
+23
-17
No files matched your search
@@ -9,7 +9,7 @@
|
||||
"NBI_PORT" : 7557,
|
||||
"FS_INTERFACE" : "0.0.0.0",
|
||||
"FS_PORT" : 7567,
|
||||
"FILES_IP" : "192.168.0.1",
|
||||
"FS_IP" : "192.168.0.1",
|
||||
"LOG_INFORMS" : true,
|
||||
"DEBUG" : false
|
||||
}
|
||||
+16
-2
@@ -20,6 +20,9 @@
|
||||
# THE SOFTWARE.
|
||||
###
|
||||
|
||||
buffer = require 'buffer'
|
||||
querystring = require 'querystring'
|
||||
|
||||
UNDEFINED_TYPE = '[object Undefined]'
|
||||
NULL_TYPE = '[object Null]'
|
||||
BOOLEAN_TYPE = '[object Boolean]'
|
||||
@@ -50,11 +53,11 @@ exports.arrayToHash = (arr) ->
|
||||
return hash
|
||||
|
||||
|
||||
exports.getDeviceId = (deviceIdStruct) ->
|
||||
exports.generateDeviceId = (deviceIdStruct) ->
|
||||
# Percent escaping function. Escapes everything except alphanumerics and underscore
|
||||
esc = (str) ->
|
||||
str.replace(/[^A-Za-z0-9_]/g, (chr) ->
|
||||
buf = new require('buffer').Buffer(chr)
|
||||
buf = new buffer.Buffer(chr, 'utf8')
|
||||
rep = ''
|
||||
rep += "%#{b.toString(16).toUpperCase()}" for b in buf
|
||||
return rep
|
||||
@@ -67,6 +70,17 @@ exports.getDeviceId = (deviceIdStruct) ->
|
||||
return "#{esc(deviceIdStruct['OUI'])}-#{esc(deviceIdStruct['SerialNumber'])}"
|
||||
|
||||
|
||||
exports.parseDeviceId = (deviceId) ->
|
||||
parts = deviceId.split('-')
|
||||
ret = {oui : querystring.unescape(parts[0])}
|
||||
if parts.length == 3
|
||||
ret.productClass = querystring.unescape(parts[1])
|
||||
ret.serialNumber = querystring.unescape(parts[2])
|
||||
else
|
||||
ret.serialNumber = querystring.unescape(parts[1])
|
||||
return ret
|
||||
|
||||
|
||||
exports.extend = (obj, mixin) ->
|
||||
obj[name] = method for name, method of mixin
|
||||
obj
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ defaults = {
|
||||
FS_PORT : 7567,
|
||||
FS_INTERFACE : '0.0.0.0',
|
||||
FS_SSL : false,
|
||||
FILES_IP : '192.168.0.1', # Used when sending download requests to devices
|
||||
FS_IP : '192.168.0.1', # Used when sending download requests to devices
|
||||
|
||||
CACHE_DURATION : 60, # in seconds
|
||||
PRESETS_CACHE_DURATION : 86400,
|
||||
|
||||
+3
-11
@@ -437,7 +437,7 @@ listener = (httpRequest, httpResponse) ->
|
||||
httpResponse.end('Session is expired')
|
||||
return
|
||||
session = {
|
||||
deviceId : common.getDeviceId(cwmpRequest.methodRequest.deviceId),
|
||||
deviceId : common.generateDeviceId(cwmpRequest.methodRequest.deviceId),
|
||||
cwmpVersion : cwmpRequest.cwmpVersion,
|
||||
sessionTimeout : cwmpRequest.sessionTimeout ? config.SESSION_TIMEOUT
|
||||
}
|
||||
@@ -499,15 +499,8 @@ listener = (httpRequest, httpResponse) ->
|
||||
presetSoftwareVersion = devicePreset.softwareVersion?.preset
|
||||
currentSoftwareVersion = devicePreset.softwareVersion?.current._value
|
||||
if presetSoftwareVersion? and presetSoftwareVersion != currentSoftwareVersion
|
||||
projection = {
|
||||
'_deviceId._Manufacturer' : 1,
|
||||
'_deviceId._ProductClass' : 1,
|
||||
}
|
||||
db.devicesCollection.findOne({'_id' : currentRequest.session.deviceId}, projection, (err, device) ->
|
||||
throw err if err
|
||||
manufacturer = device._deviceId._Manufacturer
|
||||
productClass = device._deviceId._ProductClass
|
||||
db.filesCollection.findOne({'metadata.fileType' : '1 Firmware Upgrade Image', 'metadata.manufacturer' : manufacturer, 'metadata.productClass' : productClass, 'metadata.version' : presetSoftwareVersion}, {_id : 1}, (err, file) ->
|
||||
deviceIdStruct = common.parseDeviceId(currentRequest.session.deviceId)
|
||||
db.filesCollection.findOne({'metadata.fileType' : '1 Firmware Upgrade Image', 'metadata.oui' : deviceIdStruct.oui, 'metadata.productClass' : deviceIdStruct.productClass, 'metadata.version' : presetSoftwareVersion}, {_id : 1}, (err, file) ->
|
||||
throw err if err
|
||||
if not file?
|
||||
util.error("#{currentRequest.session.deviceId}: Firmware image not found (#{presetSoftwareVersion})")
|
||||
@@ -523,7 +516,6 @@ listener = (httpRequest, httpResponse) ->
|
||||
return requestDownloadResponse()
|
||||
)
|
||||
)
|
||||
)
|
||||
else
|
||||
return requestDownloadResponse()
|
||||
)
|
||||
|
||||
+1
-1
@@ -275,7 +275,7 @@ listener = (request, response) ->
|
||||
if request.method == 'PUT'
|
||||
metadata = {
|
||||
fileType : request.headers.filetype,
|
||||
manufacturer : request.headers.manufacturer,
|
||||
oui : request.headers.oui,
|
||||
productClass : request.headers.productclass,
|
||||
version : request.headers.version,
|
||||
}
|
||||
|
||||
+1
-1
@@ -332,7 +332,7 @@ this.download = (task, methodResponse, callback) ->
|
||||
type : 'Download',
|
||||
fileType : file.metadata.fileType,
|
||||
fileSize : file.length,
|
||||
url : "http://#{config.FILES_IP}:#{config.FILES_PORT}/#{encodeURIComponent(file.filename)}",
|
||||
url : "http://#{config.FS_IP}:#{config.FS_PORT}/#{encodeURIComponent(file.filename)}",
|
||||
successUrl : task.successUrl,
|
||||
failureUrl : task.failureUrl
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user