Addes support for RequestDownload for firmware upgrade.
This commit is contained in:
1 parent
3a56909b4b
commit
8e98b0414e
3 files changed
+63
-2
No files matched your search
+43
@@ -346,6 +346,49 @@ listener = (httpRequest, httpResponse) ->
|
||||
cwmpResponse.methodResponse = {type : 'TransferCompleteResponse'}
|
||||
res = tr069.response(cwmpRequest.id, cwmpResponse, cookies)
|
||||
writeResponse(currentRequest, res)
|
||||
else if cwmpRequest.methodRequest.type is 'RequestDownload'
|
||||
fileType = cwmpRequest.methodRequest.fileType
|
||||
util.log("#{currentRequest.deviceId}: RequestDownload (#{fileType})")
|
||||
if fileType isnt '1 Firmware Upgrade Image'
|
||||
# Only supporting firmware upgrade for now
|
||||
cwmpResponse.methodResponse = {type : 'RequestDownloadResponse'}
|
||||
res = tr069.response(cwmpRequest.id, cwmpResponse, cookies)
|
||||
writeResponse(currentRequest, res)
|
||||
return
|
||||
|
||||
db.getPresets((allPresets, allObjects) ->
|
||||
presets.getDevicePreset(currentRequest.deviceId, allPresets, allObjects, (devicePreset) ->
|
||||
presetSoftwareVersion = devicePreset.softwareVersion?.preset
|
||||
currentSoftwareVersion = devicePreset.softwareVersion?.current._value
|
||||
if presetSoftwareVersion? and presetSoftwareVersion != currentSoftwareVersion
|
||||
projection = {
|
||||
'InternetGatewayDevice.DeviceInfo.Manufacturer' : 1,
|
||||
'InternetGatewayDevice.DeviceInfo.ProductClass' : 1,
|
||||
}
|
||||
db.devicesCollection.findOne({'_id' : currentRequest.deviceId}, projection, (err, device) ->
|
||||
manufacturer = device.InternetGatewayDevice.DeviceInfo.Manufacturer._value
|
||||
productClass = device.InternetGatewayDevice.DeviceInfo.ProductClass._value
|
||||
db.filesCollection.findOne({'metadata.Manufacturer' : manufacturer, 'metadata.ProductClass' : productClass, 'metadata.SoftwareVersion' : presetSoftwareVersion}, {_id : 1}, (err, file) ->
|
||||
throw err if err
|
||||
task = {
|
||||
device : currentRequest.deviceId,
|
||||
name : 'download',
|
||||
file : file['_id']
|
||||
}
|
||||
apiFunctions.insertTasks(task, (err, tasks) ->
|
||||
throw err if err
|
||||
cwmpResponse.methodResponse = {type : 'RequestDownloadResponse'}
|
||||
res = tr069.response(cwmpRequest.id, cwmpResponse, cookies)
|
||||
writeResponse(currentRequest, res)
|
||||
)
|
||||
)
|
||||
)
|
||||
else
|
||||
cwmpResponse.methodResponse = {type : 'RequestDownloadResponse'}
|
||||
res = tr069.response(cwmpRequest.id, cwmpResponse, cookies)
|
||||
writeResponse(currentRequest, res)
|
||||
)
|
||||
)
|
||||
else
|
||||
throw Error('ACS method not supported')
|
||||
else if cwmpRequest.methodResponse?
|
||||
|
||||
+4
-2
@@ -348,7 +348,7 @@ this.download = (task, methodResponse, callback) ->
|
||||
return
|
||||
|
||||
if methodResponse.type isnt 'DownloadResponse'
|
||||
db.filesCollection.findOne({_id : mongodb.ObjectID(task.file)}, (err, file) ->
|
||||
db.filesCollection.findOne({_id : mongodb.ObjectID(String(task.file))}, (err, file) ->
|
||||
if not file?
|
||||
callback('File not found')
|
||||
return
|
||||
@@ -360,7 +360,9 @@ this.download = (task, methodResponse, callback) ->
|
||||
type : 'Download',
|
||||
fileType : file.metadata?.FileType ? '1 Firmware Upgrade Image',
|
||||
fileSize : file.length,
|
||||
url : "http://#{config.FILES_IP}:#{config.FILES_PORT}/#{file.filename}"
|
||||
url : "http://#{config.FILES_IP}:#{config.FILES_PORT}/#{file.filename}",
|
||||
successUrl : task.successUrl,
|
||||
failureUrl : task.failureUrl
|
||||
}
|
||||
callback(null, STATUS_STARTED, {methodRequest : methodRequest})
|
||||
)
|
||||
|
||||
@@ -198,6 +198,17 @@ acsTransferCompleteResponse = (xml, methodRequest) ->
|
||||
xml.node('cwmp:TransferCompleteResponse').text('')
|
||||
|
||||
|
||||
acsRequestDownload = (xml) ->
|
||||
# TODO FileTypeArg
|
||||
{
|
||||
fileType : xml.get('FileType').text()
|
||||
}
|
||||
|
||||
|
||||
acsRequestDownloadResponse = (xml, methodRequest) ->
|
||||
xml.node('cwmp:RequestDownloadResponse').text('')
|
||||
|
||||
|
||||
exports.request = (httpRequest) ->
|
||||
cwmpRequest = {cookies: {}}
|
||||
cwmpRequest.cookies = cookiesToObj(httpRequest.headers.cookie) if httpRequest.headers.cookie
|
||||
@@ -225,6 +236,9 @@ exports.request = (httpRequest) ->
|
||||
when 'TransferComplete'
|
||||
cwmpRequest.methodRequest = acsTransferComplete(methodElement)
|
||||
cwmpRequest.methodRequest.type = 'TransferComplete'
|
||||
when 'RequestDownload'
|
||||
cwmpRequest.methodRequest = acsRequestDownload(methodElement)
|
||||
cwmpRequest.methodRequest.type = 'RequestDownload'
|
||||
when 'GetParameterNamesResponse'
|
||||
cwmpRequest.methodResponse = cpeGetParameterNamesResponse(methodElement)
|
||||
cwmpRequest.methodResponse.type = 'GetParameterNamesResponse'
|
||||
@@ -289,6 +303,8 @@ exports.response = (id, cwmpResponse, cookies = null) ->
|
||||
acsInformResponse(body)
|
||||
when 'TransferCompleteResponse'
|
||||
acsTransferCompleteResponse(body)
|
||||
when 'RequestDownloadResponse'
|
||||
acsRequestDownloadResponse(body)
|
||||
else
|
||||
throw Error("Unknown method response type #{cwmpResponse.methodResponse.type}")
|
||||
else if cwmpResponse.methodRequest?
|
||||
|
||||
Reference in new issue
Block a user