Skip to content

Commit

Permalink
Merge pull request #1844 from akorb/s09-multiple-iids
Browse files Browse the repository at this point in the history
Multiple IIDs are possible in a single request
  • Loading branch information
gpotter2 committed Feb 22, 2019
2 parents 66d2cd7 + 54948fb commit b1b1fc8
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 150 deletions.
18 changes: 10 additions & 8 deletions doc/scapy/advanced_usage.rst
Expand Up @@ -1901,7 +1901,7 @@ OBD message
-------------

OBD is implemented on top of ISOTP. Use an ISOTPSocket for the communication with a ECU.
You should set the parameter `basecls=OBD` in your ISOTPSocket init call.
You should set the parameters `basecls=OBD` and `padding=True` in your ISOTPSocket init call.

OBD is split into different service groups. Here are some example requests:

Expand All @@ -1922,7 +1922,7 @@ The response will contain a PacketListField, called `data_records`. This field c
|###[ PID_00_PIDsSupported ]###
| supported_pids= PID20+PID1F+PID1C+PID15+PID14+PID13+PID11+PID10+PID0F+PID0E+PID0D+PID0C+PID0B+PID0A+PID07+PID06+PID05+PID04+PID03+PID01

Lets assume our ECU under test supports the pid 0x15::
Let's assume our ECU under test supports the pid 0x15::
req = OBD()/OBD_S01(pid=[0x15])
resp = sock.sr1(req)
Expand Down Expand Up @@ -1951,7 +1951,7 @@ Examples:

Request supported Information Identifiers::

req = OBD()/OBD_S09(iid=0x00)
req = OBD()/OBD_S09(iid=[0x00])

Request the Vehicle Identification Number (VIN)::

Expand All @@ -1960,11 +1960,13 @@ Request the Vehicle Identification Number (VIN)::
resp.show()
###[ On-board diagnostics ]###
service= VehicleInformationResponse
###[ S9_VehicleInformationPositiveResponse ]###
iid= 0x2
###[ IID_02_VehicleIdentificationNumber ]###
count= 1
vehicle_identification_numbers= ['W0L000051T2123456']
###[ Infotype IDs ]###
\data_records\
|###[ OBD_S09_IID_Record ]###
| iid= 0x2
|###[ IID_02_VehicleIdentificationNumber ]###
| count= 1
| vehicle_identification_numbers= ['W0L000051T2123456']


Expand Down
48 changes: 38 additions & 10 deletions scapy/contrib/automotive/obd/iid/iids.py
Expand Up @@ -7,15 +7,29 @@
# scapy.contrib.status = skip

from scapy.fields import FieldLenField, FieldListField, StrFixedLenField, \
ByteField, ShortField, FlagsField
from scapy.packet import Packet
ByteField, ShortField, FlagsField, XByteField, PacketListField
from scapy.contrib.automotive.obd.packet import OBD_Packet
from scapy.packet import Packet, bind_layers


# See https://en.wikipedia.org/wiki/OBD-II_PIDs#Service_09
# for further information
# IID = Information IDentification

class OBD_IID00(Packet):
class OBD_S09_IID_Record(Packet):
fields_desc = [
XByteField("iid", 1),
]


class OBD_S09_IID(Packet):
name = "Infotype IDs"
fields_desc = [
PacketListField("data_records", None, OBD_S09_IID_Record)
]


class OBD_IID00(OBD_Packet):
name = "IID_00_Service9SupportedInformationTypes"
fields_desc = [
FlagsField('supported_iids', b'', 32, [
Expand Down Expand Up @@ -55,7 +69,7 @@ class OBD_IID00(Packet):
]


class _OBD_IID_MessageCount(Packet):
class _OBD_IID_MessageCount(OBD_Packet):
fields_desc = [
ByteField('message_count', 0)
]
Expand All @@ -81,7 +95,7 @@ class OBD_IID09(_OBD_IID_MessageCount):
name = "IID_09_EcuNameMessageCount"


class OBD_IID02(Packet):
class OBD_IID02(OBD_Packet):
name = "IID_02_VehicleIdentificationNumber"
fields_desc = [
FieldLenField('count', None, count_of='vehicle_identification_numbers',
Expand All @@ -92,7 +106,7 @@ class OBD_IID02(Packet):
]


class OBD_IID04(Packet):
class OBD_IID04(OBD_Packet):
name = "IID_04_CalibrationId"
fields_desc = [
FieldLenField('count', None, count_of='calibration_identifications',
Expand All @@ -103,7 +117,7 @@ class OBD_IID04(Packet):
]


class OBD_IID06(Packet):
class OBD_IID06(OBD_Packet):
name = "IID_06_CalibrationVerificationNumbers"
fields_desc = [
FieldLenField('count', None,
Expand All @@ -114,7 +128,7 @@ class OBD_IID06(Packet):
]


class OBD_IID08(Packet):
class OBD_IID08(OBD_Packet):
name = "IID_08_InUsePerformanceTracking"
fields_desc = [
FieldLenField('count', None, count_of='data', fmt='B'),
Expand All @@ -124,7 +138,7 @@ class OBD_IID08(Packet):
]


class OBD_IID0A(Packet):
class OBD_IID0A(OBD_Packet):
name = "IID_0A_EcuName"
fields_desc = [
FieldLenField('count', None, count_of='ecu_names', fmt='B'),
Expand All @@ -134,11 +148,25 @@ class OBD_IID0A(Packet):
]


class OBD_IID0B(Packet):
class OBD_IID0B(OBD_Packet):
name = "IID_0B_InUsePerformanceTrackingForCompressionIgnitionVehicles"
fields_desc = [
FieldLenField('count', None, count_of='data', fmt='B'),
FieldListField('data', None,
ShortField(b'', 0),
count_from=lambda pkt: pkt.count)
]


bind_layers(OBD_S09_IID_Record, OBD_IID00, iid=0x00)
bind_layers(OBD_S09_IID_Record, OBD_IID01, iid=0x01)
bind_layers(OBD_S09_IID_Record, OBD_IID02, iid=0x02)
bind_layers(OBD_S09_IID_Record, OBD_IID03, iid=0x03)
bind_layers(OBD_S09_IID_Record, OBD_IID04, iid=0x04)
bind_layers(OBD_S09_IID_Record, OBD_IID05, iid=0x05)
bind_layers(OBD_S09_IID_Record, OBD_IID06, iid=0x06)
bind_layers(OBD_S09_IID_Record, OBD_IID07, iid=0x07)
bind_layers(OBD_S09_IID_Record, OBD_IID08, iid=0x08)
bind_layers(OBD_S09_IID_Record, OBD_IID09, iid=0x09)
bind_layers(OBD_S09_IID_Record, OBD_IID0A, iid=0x0A)
bind_layers(OBD_S09_IID_Record, OBD_IID0B, iid=0x0B)
18 changes: 1 addition & 17 deletions scapy/contrib/automotive/obd/obd.py
Expand Up @@ -83,22 +83,6 @@ def answers(self, other):
bind_layers(OBD, OBD_S06_MID, service=0x46)
bind_layers(OBD, OBD_S07_DTC, service=0x47)
bind_layers(OBD, OBD_S08_TID, service=0x48)
bind_layers(OBD, OBD_S09_PR, service=0x49)
bind_layers(OBD, OBD_S09_IID, service=0x49)
bind_layers(OBD, OBD_S0A_DTC, service=0x4A)
bind_layers(OBD, OBD_NR, service=0x7F)


# Service 09 Bindings

bind_layers(OBD_S09_PR, OBD_IID00, iid=0x00)
bind_layers(OBD_S09_PR, OBD_IID01, iid=0x01)
bind_layers(OBD_S09_PR, OBD_IID02, iid=0x02)
bind_layers(OBD_S09_PR, OBD_IID03, iid=0x03)
bind_layers(OBD_S09_PR, OBD_IID04, iid=0x04)
bind_layers(OBD_S09_PR, OBD_IID05, iid=0x05)
bind_layers(OBD_S09_PR, OBD_IID06, iid=0x06)
bind_layers(OBD_S09_PR, OBD_IID07, iid=0x07)
bind_layers(OBD_S09_PR, OBD_IID08, iid=0x08)
bind_layers(OBD_S09_PR, OBD_IID09, iid=0x09)
bind_layers(OBD_S09_PR, OBD_IID0A, iid=0x0A)
bind_layers(OBD_S09_PR, OBD_IID0B, iid=0x0B)

0 comments on commit b1b1fc8

Please sign in to comment.