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