Addes support for RequestDownload for firmware upgrade.

This commit is contained in:
Zaid Abdulla committed 2013-10-18 15:25:18 +03:00
1 parent 3a56909b4b
commit 8e98b0414e
3 files changed
+63 -2

No files matched your search

+43
View File
@@ -346,6 +346,49 @@ listener = (httpRequest, httpResponse) ->
cwmpResponse.methodResponse = {type : 'TransferCompleteResponse'} cwmpResponse.methodResponse = {type : 'TransferCompleteResponse'}
res = tr069.response(cwmpRequest.id, cwmpResponse, cookies) res = tr069.response(cwmpRequest.id, cwmpResponse, cookies)
writeResponse(currentRequest, res) 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 else
throw Error('ACS method not supported') throw Error('ACS method not supported')
else if cwmpRequest.methodResponse? else if cwmpRequest.methodResponse?
+4 -2
View File
@@ -348,7 +348,7 @@ this.download = (task, methodResponse, callback) ->
return return
if methodResponse.type isnt 'DownloadResponse' 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? if not file?
callback('File not found') callback('File not found')
return return
@@ -360,7 +360,9 @@ this.download = (task, methodResponse, callback) ->
type : 'Download', type : 'Download',
fileType : file.metadata?.FileType ? '1 Firmware Upgrade Image', fileType : file.metadata?.FileType ? '1 Firmware Upgrade Image',
fileSize : file.length, 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}) callback(null, STATUS_STARTED, {methodRequest : methodRequest})
) )
+16
View File
@@ -198,6 +198,17 @@ acsTransferCompleteResponse = (xml, methodRequest) ->
xml.node('cwmp:TransferCompleteResponse').text('') 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) -> exports.request = (httpRequest) ->
cwmpRequest = {cookies: {}} cwmpRequest = {cookies: {}}
cwmpRequest.cookies = cookiesToObj(httpRequest.headers.cookie) if httpRequest.headers.cookie cwmpRequest.cookies = cookiesToObj(httpRequest.headers.cookie) if httpRequest.headers.cookie
@@ -225,6 +236,9 @@ exports.request = (httpRequest) ->
when 'TransferComplete' when 'TransferComplete'
cwmpRequest.methodRequest = acsTransferComplete(methodElement) cwmpRequest.methodRequest = acsTransferComplete(methodElement)
cwmpRequest.methodRequest.type = 'TransferComplete' cwmpRequest.methodRequest.type = 'TransferComplete'
when 'RequestDownload'
cwmpRequest.methodRequest = acsRequestDownload(methodElement)
cwmpRequest.methodRequest.type = 'RequestDownload'
when 'GetParameterNamesResponse' when 'GetParameterNamesResponse'
cwmpRequest.methodResponse = cpeGetParameterNamesResponse(methodElement) cwmpRequest.methodResponse = cpeGetParameterNamesResponse(methodElement)
cwmpRequest.methodResponse.type = 'GetParameterNamesResponse' cwmpRequest.methodResponse.type = 'GetParameterNamesResponse'
@@ -289,6 +303,8 @@ exports.response = (id, cwmpResponse, cookies = null) ->
acsInformResponse(body) acsInformResponse(body)
when 'TransferCompleteResponse' when 'TransferCompleteResponse'
acsTransferCompleteResponse(body) acsTransferCompleteResponse(body)
when 'RequestDownloadResponse'
acsRequestDownloadResponse(body)
else else
throw Error("Unknown method response type #{cwmpResponse.methodResponse.type}") throw Error("Unknown method response type #{cwmpResponse.methodResponse.type}")
else if cwmpResponse.methodRequest? else if cwmpResponse.methodRequest?