Skip to content

Commit

Permalink
[lua] generalize unknown and reserved fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhyde committed May 27, 2024
1 parent 809c793 commit 501c2aa
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 85 deletions.
147 changes: 73 additions & 74 deletions proto/fields.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
local vs = require("proto.valuestrings")

local fields = {
-- header and command fields
head = ProtoField.string("ipc.head", "Head"),
cmd_length = ProtoField.uint32("ipc.len", "Command Length"),
cmd = ProtoField.uint32("ipc.cmd", "Command", base.HEX),
cmdType = ProtoField.uint32("ipc.cmdType", "Type", base.HEX, vs.ipc_cmd, 0x0FFFFFFF),
direction = ProtoField.uint8("ipc.direction", "Direction", base.DEC, vs.direction, 0x0F000000),
cmdId = ProtoField.uint8("ipc.cmdId", "Command ID", base.DEC),
cmdVer = ProtoField.uint8("ipc.cmdVer", "Command Version", base.DEC),
data_length = ProtoField.uint32("ipc.len", "Data Length"),
-- header and command fields
head = ProtoField.string("ipc.head", "Head"),
cmd_length = ProtoField.uint32("ipc.len", "Command Length"),
cmd = ProtoField.uint32("ipc.cmd", "Command", base.HEX),
cmdType = ProtoField.uint32("ipc.cmdType", "Type", base.HEX, vs.ipc_cmd, 0x0FFFFFFF),
direction = ProtoField.uint8("ipc.direction", "Direction", base.DEC, vs.direction, 0x0F000000),
cmdId = ProtoField.uint8("ipc.cmdId", "Command ID", base.DEC),
cmdVer = ProtoField.uint8("ipc.cmdVer", "Command Version", base.DEC),
data_length = ProtoField.uint32("ipc.len", "Data Length"),

-- generic fields
error = ProtoField.uint32("ipc.error", "Error", base.HEX, vs.net_error),
mac = ProtoField.bytes("ipc.device.mac", "MAC", base.COLON),
protocolVer = ProtoField.uint32("ipc.device.protocolVer", "Protocol Version", base.DEC, vs.version),

-- generic fields
error = ProtoField.uint32("ipc.error", "Error", base.HEX, vs.net_error),
-- init fields
flag = ProtoField.string("ipc.init.flag", "Flag"),
devType = ProtoField.uint32("ipc.init.devType", "Device Type", base.DEC),
Expand All @@ -27,73 +30,69 @@ local fields = {
supportSoftEncrypt = ProtoField.uint32("ipc.init.supportSoftEncrypt", "Support Soft Encryption", base.DEC),
transportEncryptType = ProtoField.uint8("ipc.init.transportEncryptType", "Transport Encryption Type", base.DEC),

-- login fields
connectType = ProtoField.uint32("ipc.login.connectType", "Connect Type"),
username = ProtoField.bytes("ipc.login.username", "Username", base.SPACE),
password = ProtoField.bytes("ipc.login.password", "Password", base.SPACE),
computerName = ProtoField.string("ipc.login.computerName", "Computer Name"),
ip = ProtoField.string("ipc.login.ip", "IP"),
mac = ProtoField.string("ipc.login.mac", "MAC"),
productType = ProtoField.uint8("ipc.login.productType", "Product Type"),
resv = ProtoField.uint8("ipc.login.resv", "Resv"),
netProtocolVer = ProtoField.uint32("ipc.login.netProtocolVer", "Net Protocol Version"),
-- login fields
connectType = ProtoField.uint32("ipc.login.connectType", "Connect Type"),
username = ProtoField.bytes("ipc.login.username", "Username", base.SPACE),
password = ProtoField.bytes("ipc.login.password", "Password", base.SPACE),
computerName = ProtoField.string("ipc.login.computerName", "Computer Name"),
ip = ProtoField.string("ipc.login.ip", "IP"),
productType = ProtoField.uint8("ipc.login.productType", "Product Type"),

-- config fields
ConfigDataLen = ProtoField.uint32("ipc.config.ConfigDataLen", "ConfigDataLen", base.DEC),
PTZPresetNum = ProtoField.uint32("ipc.config.PTZPresetNum", "PTZPresetNum", base.DEC),
PTZCruiseNum = ProtoField.uint32("ipc.config.PTZCruiseNum", "PTZCruiseNum", base.DEC),
PTZPresetNumForCruise = ProtoField.uint32("ipc.config.PTZPresetNumForCruise", "PTZPresetNumForCruise", base.DEC),
PresetNameMaxLen = ProtoField.uint32("ipc.config.PresetNameMaxLen", "PresetNameMaxLen", base.DEC),
CruiseNameMaxLen = ProtoField.uint32("ipc.config.CruiseNameMaxLen", "CruiseNameMaxLen", base.DEC),
bSupportPTZ = ProtoField.uint8("ipc.config.bSupportPTZ", "bSupportPTZ", base.DEC),
videoFormat = ProtoField.uint8("ipc.config.videoFormat", "videoFormat", base.DEC),
sensorInNum = ProtoField.uint8("ipc.config.sensorInNum", "sensorInNum", base.DEC),
alarmOutNum = ProtoField.uint8("ipc.config.alarmOutNum", "alarmOutNum", base.DEC),
ucStreamCount = ProtoField.uint8("ipc.config.ucStreamCount", "ucStreamCount", base.DEC),
bSupportSnap = ProtoField.uint8("ipc.config.bSupportSnap", "bSupportSnap", base.DEC),
noused = ProtoField.uint8("ipc.config.noused", "noused", base.DEC),
ucLiveAudioStream = ProtoField.uint8("ipc.config.ucLiveAudioStream", "ucLiveAudioStream", base.DEC),
ucTalkAudioStream = ProtoField.uint8("ipc.config.ucTalkAudioStream", "ucTalkAudioStream", base.DEC),
audioEncodeType = ProtoField.uint8("ipc.config.audioEncodeType", "audioEncodeType", base.DEC),
audioBitWidth = ProtoField.uint8("ipc.config.audioBitWidth", "audioBitWidth", base.DEC),
audioChannel = ProtoField.uint8("ipc.config.audioChannel", "audioChannel", base.DEC),
dwAudioSample = ProtoField.uint32("ipc.config.dwAudioSample", "dwAudioSample", base.DEC),
UserRight = ProtoField.uint32("ipc.config.UserRight", "UserRight", base.DEC),
softwareVer = ProtoField.bytes("ipc.config.softwareVer", "softwareVer", base.DOT),
buildDate = ProtoField.uint32("ipc.config.buildDate", "buildDate", base.DEC),
MAC = ProtoField.bytes("ipc.config.MAC", "MAC", base.COLON),
deviceName = ProtoField.string("ipc.config.deviceName", "deviceName"),
nCustomerID = ProtoField.uint32("ipc.config.nCustomerID", "nCustomerID", base.DEC),
defBrightness = ProtoField.uint8("ipc.config.defBrightness", "defBrightness", base.DEC),
defContrast = ProtoField.uint8("ipc.config.defContrast", "defContrast", base.DEC),
defHue = ProtoField.uint8("ipc.config.defHue", "defHue", base.DEC),
defSaturation = ProtoField.uint8("ipc.config.defSaturation", "defSaturation", base.DEC),
nosupportPTZ = ProtoField.uint8("ipc.config.nosupportPTZ", "nosupportPTZ", base.DEC),
bspeedDomePTZ = ProtoField.uint8("ipc.config.bspeedDomePTZ", "bspeedDomePTZ", base.DEC),
framerate = ProtoField.uint8("ipc.config.framerate", "framerate", base.DEC),
bSupportSetSubStream = ProtoField.uint8("ipc.config.bSupportSetSubStream", "bSupportSetSubStream", base.DEC),
_bf_68 = ProtoField.uint32("ipc.config._bf_68", "_bf_68", base.DEC),
supportPassThroughApi = ProtoField.uint8("ipc.config.supportPassThroughApi", "supportPassThroughApi", base.DEC),
bSupportMultiChannel = ProtoField.uint8("ipc.config.bSupportMultiChannel", "bSupportMultiChannel", base.DEC),
noused2 = ProtoField.bytes("ipc.config.noused2", "noused2"),
apiVersion = ProtoField.uint32("ipc.config.apiVersion", "apiVersion", base.DEC),
binaryVersion = ProtoField.uint32("ipc.config.binaryVersion", "binaryVersion", base.DEC),
_bf_78 = ProtoField.uint32("ipc.config._bf_78", "_bf_78", base.DEC),
noused1 = ProtoField.bytes("ipc.config.noused1", "noused1"),
-- config fields
ConfigDataLen = ProtoField.uint32("ipc.config.ConfigDataLen", "ConfigDataLen", base.DEC),
PTZPresetNum = ProtoField.uint32("ipc.config.PTZPresetNum", "PTZPresetNum", base.DEC),
PTZCruiseNum = ProtoField.uint32("ipc.config.PTZCruiseNum", "PTZCruiseNum", base.DEC),
PTZPresetNumForCruise = ProtoField.uint32("ipc.config.PTZPresetNumForCruise", "PTZPresetNumForCruise", base.DEC),
PresetNameMaxLen = ProtoField.uint32("ipc.config.PresetNameMaxLen", "PresetNameMaxLen", base.DEC),
CruiseNameMaxLen = ProtoField.uint32("ipc.config.CruiseNameMaxLen", "CruiseNameMaxLen", base.DEC),
bSupportPTZ = ProtoField.uint8("ipc.config.bSupportPTZ", "bSupportPTZ", base.DEC),
videoFormat = ProtoField.uint8("ipc.config.videoFormat", "videoFormat", base.DEC),
sensorInNum = ProtoField.uint8("ipc.config.sensorInNum", "sensorInNum", base.DEC),
alarmOutNum = ProtoField.uint8("ipc.config.alarmOutNum", "alarmOutNum", base.DEC),
ucStreamCount = ProtoField.uint8("ipc.config.ucStreamCount", "ucStreamCount", base.DEC),
bSupportSnap = ProtoField.uint8("ipc.config.bSupportSnap", "bSupportSnap", base.DEC),
ucLiveAudioStream = ProtoField.uint8("ipc.config.ucLiveAudioStream", "ucLiveAudioStream", base.DEC),
ucTalkAudioStream = ProtoField.uint8("ipc.config.ucTalkAudioStream", "ucTalkAudioStream", base.DEC),
audioEncodeType = ProtoField.uint8("ipc.config.audioEncodeType", "audioEncodeType", base.DEC),
audioBitWidth = ProtoField.uint8("ipc.config.audioBitWidth", "audioBitWidth", base.DEC),
audioChannel = ProtoField.uint8("ipc.config.audioChannel", "audioChannel", base.DEC),
dwAudioSample = ProtoField.uint32("ipc.config.dwAudioSample", "dwAudioSample", base.DEC),
UserRight = ProtoField.uint32("ipc.config.UserRight", "UserRight", base.DEC),
softwareVer = ProtoField.bytes("ipc.config.softwareVer", "softwareVer", base.DOT),
buildDate = ProtoField.uint32("ipc.config.buildDate", "buildDate", base.DEC),
deviceName = ProtoField.string("ipc.config.deviceName", "deviceName"),
nCustomerID = ProtoField.uint32("ipc.config.nCustomerID", "nCustomerID", base.DEC),
defBrightness = ProtoField.uint8("ipc.config.defBrightness", "defBrightness", base.DEC),
defContrast = ProtoField.uint8("ipc.config.defContrast", "defContrast", base.DEC),
defHue = ProtoField.uint8("ipc.config.defHue", "defHue", base.DEC),
defSaturation = ProtoField.uint8("ipc.config.defSaturation", "defSaturation", base.DEC),
noSupportPTZ = ProtoField.uint8("ipc.config.noSupportPTZ", "noSupportPTZ", base.DEC),
speedDomePTZ = ProtoField.uint8("ipc.config.speedDomePTZ", "speedDomePTZ", base.DEC),
framerate = ProtoField.uint8("ipc.config.framerate", "framerate", base.DEC),
bSupportSetSubStream = ProtoField.uint8("ipc.config.bSupportSetSubStream", "bSupportSetSubStream", base.DEC),
_bf_68 = ProtoField.uint32("ipc.config._bf_68", "_bf_68", base.DEC),
supportPassThroughApi = ProtoField.uint8("ipc.config.supportPassThroughApi", "supportPassThroughApi", base.DEC),
bSupportMultiChannel = ProtoField.uint8("ipc.config.bSupportMultiChannel", "bSupportMultiChannel", base.DEC),
apiVersion = ProtoField.uint32("ipc.config.apiVersion", "apiVersion", base.DEC),
binaryVersion = ProtoField.uint32("ipc.config.binaryVersion", "binaryVersion", base.DEC),
_bf_78 = ProtoField.uint32("ipc.config._bf_78", "_bf_78", base.DEC),

-- alarm fields
channelId = ProtoField.uint32("ipc.alarm.channelId", "ChannelId"),
-- alarm fields
channelId = ProtoField.uint32("ipc.alarm.channelId", "Channel ID"),

-- http fields
httpDataLen = ProtoField.uint32("ipc.http.dataLen", "HTTP Data Length"),
httpSeq = ProtoField.uint32("ipc.http.seq", "Sequence"),
httpReverse = ProtoField.bytes("ipc.http.reverse", "Reverse"),
httpContent = ProtoField.string("ipc.http.content", "Content"),
httpEndByte = ProtoField.uint8("ipc.http.endByte", "End Byte"),
-- http fields
httpDataLen = ProtoField.uint32("ipc.http.dataLen", "HTTP Data Length"),
httpSeq = ProtoField.uint32("ipc.http.seq", "Sequence"),
httpReverse = ProtoField.bytes("ipc.http.reverse", "Reverse"),
httpContent = ProtoField.string("ipc.http.content", "Content"),
httpEndByte = ProtoField.uint8("ipc.http.endByte", "End Byte"),

unk8 = ProtoField.uint8("ipc.unk8", "Unknown"),
unk32 = ProtoField.uint32("ipc.unk32", "Unknown"),
unkb = ProtoField.bytes("ipc.unkb", "Unknown", base.SPACE)
-- unknown and reserved fields
reservedBytes = ProtoField.bytes("ipc.reserved.bytes", "Reserved", base.SPACE),
notUsedBytes = ProtoField.bytes("ipc.notUsed.bytes", "Not Used", base.SPACE),
unknownBytes = ProtoField.bytes("ipc.unk.bytes", "Unknown", base.SPACE),
unknownShort = ProtoField.uint8("ipc.unk.short", "Unknown"),
unknownInt = ProtoField.uint32("ipc.unk.int", "Unknown"),
}

return fields
2 changes: 1 addition & 1 deletion proto/ipc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function protocol.dissector(buffer, pinfo, root)
-- handle the rest of the data if any
if buffer:len() > offset then
local t_unknown = t_command:add(protocol, buffer(offset), "Unknown")
t_unknown:add_le(fields.unkb, buffer(offset))
t_unknown:add_le(fields.unknownBytes, buffer(offset))
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions proto/struct/CMD_REPLY_LOGIN_SUCC.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local function struct(table, fields, buffer, offset)
table:add_le(fields.alarmOutNum, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.ucStreamCount, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.bSupportSnap, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.noused, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.notUsedBytes, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.ucLiveAudioStream, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.ucTalkAudioStream, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.audioEncodeType, buffer(offset, 1)); offset = offset + 1
Expand All @@ -21,27 +21,27 @@ local function struct(table, fields, buffer, offset)
table:add_le(fields.UserRight, buffer(offset, 4)); offset = offset + 4
table:add(fields.softwareVer, buffer(offset, 4)); offset = offset + 4
table:add_le(fields.buildDate, buffer(offset, 4)); offset = offset + 4
table:add_le(fields.MAC, buffer(offset, 6)); offset = offset + 6
table:add_le(fields.mac, buffer(offset, 6)); offset = offset + 6
table:add_le(fields.deviceName, buffer(offset, 34)); offset = offset + 34
table:add_le(fields.nCustomerID, buffer(offset, 4)); offset = offset + 4
table:add_le(fields.defBrightness, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.defContrast, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.defHue, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.defSaturation, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.nosupportPTZ, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.bspeedDomePTZ, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.noSupportPTZ, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.speedDomePTZ, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.framerate, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.bSupportSetSubStream, buffer(offset, 1)); offset = offset + 1
table:add_le(fields._bf_68, buffer(offset, 4)); offset = offset + 4
table:add_le(fields.supportPassThroughApi, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.bSupportMultiChannel, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.noused2, buffer(offset, 2)); offset = offset + 2
table:add_le(fields.notUsedBytes, buffer(offset, 2)); offset = offset + 2
table:add_le(fields.apiVersion, buffer(offset, 4)); offset = offset + 4
table:add_le(fields.binaryVersion, buffer(offset, 4)); offset = offset + 4
table:add_le(fields._bf_78, buffer(offset, 4)); offset = offset + 4
table:add_le(fields.noused1, buffer(offset, 74)); offset = offset + 74
table:add_le(fields.unk8, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.unk8, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.notUsedBytes, buffer(offset, 74)); offset = offset + 74
table:add_le(fields.unknownShort, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.unknownShort, buffer(offset, 1)); offset = offset + 1
return offset
end

Expand Down
4 changes: 2 additions & 2 deletions proto/struct/CMD_REQUEST_LOGIN.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ local function struct(table, fields, buffer, offset)
table:add(fields.ip, buffer(offset, 8)); offset = offset + 8
table:add(fields.mac, buffer(offset, 6)); offset = offset + 6
table:add(fields.productType, buffer(offset, 1)); offset = offset + 1
table:add(fields.resv, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.netProtocolVer, buffer(offset, 4)); offset = offset + 4
table:add(fields.reservedBytes, buffer(offset, 1)); offset = offset + 1
table:add_le(fields.protocolVer, buffer(offset, 4)); offset = offset + 4
return offset
end

Expand Down

0 comments on commit 501c2aa

Please sign in to comment.