| -- Copyright 2013 codestation | |
| -- | |
| -- Licensed under the Apache License, Version 2.0 (the "License"); | |
| -- you may not use this file except in compliance with the License. | |
| -- You may obtain a copy of the License at | |
| -- | |
| -- http://www.apache.org/licenses/LICENSE-2.0 | |
| -- | |
| -- Unless required by applicable law or agreed to in writing, software | |
| -- distributed under the License is distributed on an "AS IS" BASIS, | |
| -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| -- See the License for the specific language governing permissions and | |
| -- limitations under the License. | |
| vitacma_proto = Proto("vitacma","PSV CMA protocol") | |
| function decode_ptpip_cmd(code) | |
| if code == 1 then | |
| return "PTPIP_INIT_COMMAND_REQUEST" | |
| elseif code == 2 then | |
| return "PTPIP_INIT_COMMAND_ACK" | |
| elseif code == 3 then | |
| return "PTPIP_INIT_EVENT_REQUEST" | |
| elseif code == 4 then | |
| return "PTPIP_INIT_EVENT_ACK" | |
| elseif code == 5 then | |
| return "PTPIP_INIT_FAIL" | |
| elseif code == 6 then | |
| return "PTPIP_CMD_REQUEST" | |
| elseif code == 7 then | |
| return "PTPIP_CMD_RESPONSE" | |
| elseif code == 8 then | |
| return "PTPIP_EVENT" | |
| elseif code == 9 then | |
| return "PTPIP_START_DATA_PACKET" | |
| elseif code == 10 then | |
| return "PTPIP_DATA_PACKET" | |
| elseif code == 11 then | |
| return "PTPIP_CANCEL_TRANSACTION" | |
| elseif code == 12 then | |
| return "PTPIP_END_DATA_PACKET" | |
| elseif code == 13 then | |
| return "PTPIP_PING" | |
| elseif code == 14 then | |
| return "PTPIP_PONG" | |
| else | |
| return "UNKNOWN" | |
| end | |
| end | |
| function decode_vita_event(code) | |
| if code == 0xC104 then | |
| return "PTP_EC_VITA_RequestSendNumOfObject" | |
| elseif code == 0xC105 then | |
| return "PTP_EC_VITA_RequestSendObjectMetadata" | |
| elseif code == 0xC107 then | |
| return "PTP_EC_VITA_RequestSendObject" | |
| elseif code == 0xC108 then | |
| return "PTP_EC_VITA_RequestCancelTask" | |
| elseif code == 0xC10B then | |
| return "PTP_EC_VITA_RequestSendHttpObjectFromURL" | |
| elseif code == 0xC10D then | |
| return "PTP_EC_VITA_Unknown1" | |
| elseif code == 0xC10F then | |
| return "PTP_EC_VITA_RequestSendObjectStatus" | |
| elseif code == 0xC110 then | |
| return "PTP_EC_VITA_RequestSendObjectThumb" | |
| elseif code == 0xC111 then | |
| return "PTP_EC_VITA_RequestDeleteObject" | |
| elseif code == 0xC112 then | |
| return "PTP_EC_VITA_RequestGetSettingInfo" | |
| elseif code == 0xC113 then | |
| return "PTP_EC_VITA_RequestSendHttpObjectPropFromURL" | |
| elseif code == 0xC115 then | |
| return "PTP_EC_VITA_RequestSendPartOfObject" | |
| elseif code == 0xC117 then | |
| return "PTP_EC_VITA_RequestOperateObject" | |
| elseif code == 0xC118 then | |
| return "PTP_EC_VITA_RequestGetPartOfObject" | |
| elseif code == 0xC119 then | |
| return "PTP_EC_VITA_RequestSendStorageSize" | |
| elseif code == 0xC120 then | |
| return "PTP_EC_VITA_RequestCheckExistance" | |
| elseif code == 0xC122 then | |
| return "PTP_EC_VITA_RequestGetTreatObject" | |
| elseif code == 0xC123 then | |
| return "PTP_EC_VITA_RequestSendCopyConfirmationInfo" | |
| elseif code == 0xC124 then | |
| return "PTP_EC_VITA_RequestSendObjectMetadataItems" | |
| elseif code == 0xC125 then | |
| return "PTP_EC_VITA_RequestSendNPAccountInfo" | |
| elseif code == 0xC126 then | |
| return "PTP_EC_VITA_RequestTerminate" | |
| else | |
| return "UNKNOWN" | |
| end | |
| end | |
| function decode_vita_command(code) | |
| if code == 0x1002 then | |
| return "PTP_OC_OpenSession" | |
| elseif code == 0x9511 then | |
| return "PTP_OC_VITA_GetVitaInfo" | |
| elseif code == 0x9513 then | |
| return "PTP_OC_VITA_SendNumOfObject" | |
| elseif code == 0x9514 then | |
| return "PTP_OC_VITA_GetBrowseInfo" | |
| elseif code == 0x9515 then | |
| return "PTP_OC_VITA_SendObjectMetadata" | |
| elseif code == 0x9516 then | |
| return "PTP_OC_VITA_SendObjectThumb" | |
| elseif code == 0x9518 then | |
| return "PTP_OC_VITA_ReportResult" | |
| elseif code == 0x951C then | |
| return "PTP_OC_VITA_SendInitiatorInfo" | |
| elseif code == 0x951F then | |
| return "PTP_OC_VITA_GetUrl" | |
| elseif code == 0x9520 then | |
| return "PTP_OC_VITA_SendHttpObjectFromURL" | |
| elseif code == 0x9523 then | |
| return "PTP_OC_VITA_SendNPAccountInfo" | |
| elseif code == 0x9524 then | |
| return "PTP_OC_VITA_GetSettingInfo" | |
| elseif code == 0x9528 then | |
| return "PTP_OC_VITA_SendObjectStatus" | |
| elseif code == 0x9529 then | |
| return "PTP_OC_VITA_SendHttpObjectPropFromURL" | |
| elseif code == 0x952A then | |
| return "PTP_OC_VITA_SendHostStatus" | |
| elseif code == 0x952B then | |
| return "PTP_OC_VITA_SendPartOfObjectInit" | |
| elseif code == 0x952C then | |
| return "PTP_OC_VITA_SendPartOfObject" | |
| elseif code == 0x952E then | |
| return "PTP_OC_VITA_OperateObject" | |
| elseif code == 0x952F then | |
| return "PTP_OC_VITA_GetPartOfObject" | |
| elseif code == 0x9533 then | |
| return "PTP_OC_VITA_SendStorageSize" | |
| elseif code == 0x9534 then | |
| return "PTP_OC_VITA_GetTreatObject" | |
| elseif code == 0x9535 then | |
| return "PTP_OC_VITA_SendCopyConfirmationInfo" | |
| elseif code == 0x9536 then | |
| return "PTP_OC_VITA_SendObjectMetadataItems" | |
| elseif code == 0x9537 then | |
| return "PTP_OC_VITA_SendCopyConfirmationInfoInit" | |
| elseif code == 0x9538 then | |
| return "PTP_OC_VITA_KeepAlive" | |
| elseif code == 0x953A then | |
| return "PTP_OC_VITA_Unknown1" | |
| elseif code == 0x953B then | |
| return "PTP_OC_VITA_GetVitaCapabilityInfo" | |
| elseif code == 0x953C then | |
| return "PTP_OC_VITA_SendPCCapabilityInfo" | |
| else | |
| return "UNKNOWN" | |
| end | |
| end | |
| function decode_cmd_response(code) | |
| if code == 0x2000 then | |
| return "PTP_RC_Undefined" | |
| elseif code == 0x2001 then | |
| return "PTP_RC_OK" | |
| elseif code == 0x2002 then | |
| return "PTP_RC_GeneralError" | |
| elseif code == 0x2003 then | |
| return "PTP_RC_SessionNotOpen" | |
| elseif code == 0x2004 then | |
| return "PTP_RC_InvalidTransactionID" | |
| elseif code == 0x2005 then | |
| return "PTP_RC_OperationNotSupported" | |
| elseif code == 0x2006 then | |
| return "PTP_RC_ParameterNotSupported" | |
| elseif code == 0x2007 then | |
| return "PTP_RC_IncompleteTransfer" | |
| elseif code == 0x2008 then | |
| return "PTP_RC_InvalidStorageId" | |
| elseif code == 0x2009 then | |
| return "PTP_RC_InvalidObjectHandle" | |
| elseif code == 0x200A then | |
| return "PTP_RC_DevicePropNotSupported" | |
| elseif code == 0x200B then | |
| return "PTP_RC_InvalidObjectFormatCode" | |
| elseif code == 0x200C then | |
| return "PTP_RC_StoreFull" | |
| elseif code == 0x200D then | |
| return "PTP_RC_ObjectWriteProtected" | |
| elseif code == 0x200E then | |
| return "PTP_RC_StoreReadOnly" | |
| elseif code == 0x200F then | |
| return "PTP_RC_AccessDenied" | |
| elseif code == 0x2010 then | |
| return "PTP_RC_NoThumbnailPresent" | |
| elseif code == 0x2011 then | |
| return "PTP_RC_SelfTestFailed" | |
| elseif code == 0x2012 then | |
| return "PTP_RC_PartialDeletion" | |
| elseif code == 0x2013 then | |
| return "PTP_RC_StoreNotAvailable" | |
| elseif code == 0x2014 then | |
| return "PTP_RC_SpecificationByFormatUnsupported" | |
| elseif code == 0x2015 then | |
| return "PTP_RC_NoValidObjectInfo" | |
| elseif code == 0x2016 then | |
| return "PTP_RC_InvalidCodeFormat" | |
| elseif code == 0x2017 then | |
| return "PTP_RC_UnknownVendorCode" | |
| elseif code == 0x2018 then | |
| return "PTP_RC_CaptureAlreadyTerminated" | |
| elseif code == 0x2019 then | |
| return "PTP_RC_DeviceBusy" | |
| elseif code == 0x201A then | |
| return "PTP_RC_InvalidParentObject" | |
| elseif code == 0x201B then | |
| return "PTP_RC_InvalidDevicePropFormat" | |
| elseif code == 0x201C then | |
| return "PTP_RC_InvalidDevicePropValue" | |
| elseif code == 0x201D then | |
| return "PTP_RC_InvalidParameter" | |
| elseif code == 0x201E then | |
| return "PTP_RC_SessionAlreadyOpened" | |
| elseif code == 0x201F then | |
| return "PTP_RC_TransactionCanceled" | |
| else | |
| return "UNKNOWN" | |
| end | |
| end | |
| function parse_ptp_params(subtree, buffer, param_count, offset) | |
| --subtree = subtree:add(vitacma_proto,buffer(offset),"Params: " .. param_count) | |
| if param_count >= 1 then | |
| subtree:add(buffer(offset,4),"Param1: " .. string.format("%08X", buffer(offset,4):le_uint())) | |
| end | |
| if param_count >= 2 then | |
| offset = offset + 4 | |
| subtree:add(buffer(offset,4),"Param2: " .. string.format("%08X", buffer(offset,4):le_uint())) | |
| end | |
| if param_count >= 3 then | |
| offset = offset + 4 | |
| subtree:add(buffer(offset,4),"Param3: " .. string.format("%08X", buffer(offset,4):le_uint())) | |
| end | |
| if param_count >= 4 then | |
| offset = offset + 4 | |
| subtree:add(buffer(offset,4),"Param4: " .. string.format("%08X", buffer(offset,4):le_uint())) | |
| end | |
| if param_count >= 5 then | |
| offset = offset + 4 | |
| subtree:add(buffer(offset,4),"Param5: " .. string.format("%08X", buffer(offset,4):le_uint())) | |
| end | |
| end | |
| function vitacma_proto.dissector(buffer,pinfo,tree) | |
| local buflen = buffer:len() | |
| pinfo.cols.protocol = "PSV-CONTROL" | |
| if buflen > 4 and decode_ptpip_cmd(buffer(4,4):le_uint()) == "UNKNOWN" then | |
| subtree = tree:add(vitacma_proto,buffer(),"VITA CMA Payload") | |
| --subtree:add(vitacma_proto,buffer(),"Data") | |
| return | |
| else | |
| subtree = tree:add(vitacma_proto,buffer(),"VITA CMA Protocol") | |
| end | |
| if buflen > 4 then | |
| local ptpip_len = buffer(0,4):le_uint() | |
| subtree:add(buffer(0,4),"PTPIP length: " .. ptpip_len) | |
| local ptpip_type = buffer(4,4):le_uint() | |
| subtree:add(buffer(4,4),"PTPIP type: " .. ptpip_type .. " (" .. decode_ptpip_cmd(ptpip_type) .. ")") | |
| if ptpip_type == 1 then | |
| subtree:add(buffer(8),"GUID: " .. tostring(buffer(8))) | |
| elseif ptpip_type == 2 or ptpip_type == 3 then | |
| subtree:add(buffer(8,4),"Param1: " .. buffer(8,4):le_uint()) | |
| elseif ptpip_type == 4 then | |
| pinfo.cols.protocol = "PSV-EVENT" | |
| elseif ptpip_type == 6 then | |
| subtree:add(buffer(8,4),"CMD dataphase: " .. string.format("%08X", buffer(8,4):le_uint())) | |
| local vita_code = buffer(12,2):le_uint() | |
| subtree:add(buffer(12,2),"CMD code: " .. string.format("%04X", vita_code) .. " (" .. decode_vita_command(vita_code) .. ")") | |
| local ref_id = buffer(14,4):le_uint() | |
| subtree:add(buffer(14,4),"Tansaction ID: " .. ref_id) | |
| parse_ptp_params(subtree, buffer, math.floor((ptpip_len - 18) / 4), 18) | |
| elseif ptpip_type == 7 then | |
| local cmd_response = buffer(8,2):le_uint() | |
| subtree:add(buffer(8,2),"PTP response: " .. string.format("%04X", cmd_response) .. " (" .. decode_cmd_response(cmd_response) .. ")") | |
| local ref_id = buffer(10,4):le_uint() | |
| subtree:add(buffer(10,4),"Transaction ID reference: " .. ref_id) | |
| elseif ptpip_type == 8 then | |
| pinfo.cols.protocol = "PSV-EVENT" | |
| subtree = subtree:add(buffer(8),"VITA CMA Event") | |
| local vita_event = buffer(8,2):le_uint() | |
| subtree:add(buffer(8,2),"CMD code: " .. string.format("%04X", vita_event) .. " (" .. decode_vita_event(vita_event) .. ")") | |
| local ref_id = buffer(10,4):le_uint() | |
| subtree:add(buffer(10,4),"Tansaction ID: " .. ref_id) | |
| parse_ptp_params(subtree, buffer, math.floor((ptpip_len - 14) / 4), 14) | |
| elseif ptpip_type == 9 then | |
| local ref_id = buffer(8,4):le_uint() | |
| subtree:add(buffer(8,4),"Transaction ID reference: " .. ref_id) | |
| subtree:add(buffer(12,4),"Payload size: " .. buffer(12,4):le_uint()) | |
| subtree:add(buffer(16,4),"unknown: " .. buffer(16,4):le_uint()) | |
| elseif ptpip_type == 10 then | |
| local ref_id = buffer(8,4):le_uint() | |
| subtree:add(buffer(8,4),"Transaction ID reference: " .. ref_id) | |
| elseif ptpip_type == 12 then | |
| local ref_id = buffer(8,4):le_uint() | |
| subtree:add(buffer(8,4),"Tansaction ID Reference: " .. ref_id) | |
| if buflen > 12 then | |
| local payload_size = buffer(12,4):le_uint() | |
| subtree:add(buffer(12,4),"Payload size: " .. payload_size) | |
| subtree = tree:add(vitacma_proto,buffer(16),"Data (" .. payload_size .. " bytes)") | |
| end | |
| end | |
| else | |
| subtree:add(buffer(0,4),"Payload size: " .. buffer(0,4):le_uint()) | |
| end | |
| end | |
| -- load the tcp.port table | |
| tcp_table = DissectorTable.get("tcp.port") | |
| -- register our protocol to handle tcp port 999 | |
| tcp_table:add(999,vitacma_proto) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment