@@ -28,6 +28,7 @@ def commands
28
28
'busconfig' => 'Get baud configs' ,
29
29
'connect' => 'Get HW supported methods for a bus' ,
30
30
'cansend' => 'Send a CAN packet' ,
31
+ 'isotpsend' => 'Send an ISO-TP Packet and get a response' ,
31
32
'testerpresent' => 'Sends TesterPresent Pulses to the bus'
32
33
}
33
34
@@ -163,6 +164,76 @@ def cmd_cansend(*args)
163
164
success
164
165
end
165
166
167
+ #
168
+ # Generic ISO-TP CAN send packet command
169
+ #
170
+ def cmd_isotpsend ( *args )
171
+ bus = ''
172
+ id = ''
173
+ ret = ''
174
+ data = ''
175
+ timeout = nil
176
+ maxpackets = nil
177
+ cansend_opts = Rex ::Parser ::Arguments . new (
178
+ '-h' => [ false , 'Help Banner' ] ,
179
+ '-b' => [ true , 'Target bus' ] ,
180
+ '-I' => [ true , 'CAN ID' ] ,
181
+ '-R' => [ true , 'Return ID' ] ,
182
+ '-D' => [ true , 'Data packet in Hex (Do not include ISOTP command size)' ] ,
183
+ '-t' => [ true , 'Timeout value' ] ,
184
+ '-m' => [ true , 'Max packets to receive' ]
185
+ )
186
+ cansend_opts . parse ( args ) do |opt , _idx , val |
187
+ case opt
188
+ when '-h'
189
+ print_line ( "Usage: isotpsend -I <ID> -D <data>\n " )
190
+ print_line ( cansend_opts . usage )
191
+ return
192
+ when '-b'
193
+ bus = val
194
+ when '-I'
195
+ id = val
196
+ when '-R'
197
+ ret = val
198
+ when '-D'
199
+ data = val
200
+ when '-t'
201
+ timeout = val . to_i
202
+ when '-m'
203
+ maxpackets = val . to_i
204
+ end
205
+ end
206
+ bus = self . active_bus if bus . blank? && !self . active_bus . nil?
207
+ unless client . automotive . is_valid_bus? bus
208
+ print_error ( "You must specify a valid bus via -b" )
209
+ return
210
+ end
211
+ if id . blank? || data . blank?
212
+ print_error ( "You must specify a CAN ID (-I) and the data packets (-D)" )
213
+ return
214
+ end
215
+ if ret . blank?
216
+ ret = ( id . hex + 8 ) . to_s ( 16 )
217
+ print_line ( "Default return set to #{ ret } " )
218
+ end
219
+ bytes = data . scan ( /../ ) # Break up data string into 2 char (byte) chunks
220
+ if bytes . size > 8
221
+ print_error ( "Data section can only contain a max of 8 bytes (for now)" )
222
+ return result
223
+ end
224
+ opt = { }
225
+ opt [ 'TIMEOUT' ] = timeout if not timeout . nil?
226
+ opt [ 'MAXPKTS' ] = maxpackets if not maxpackets . nil?
227
+ result = client . automotive . send_isotp_and_wait_for_response ( bus , id , ret , bytes , opt )
228
+ if result . key? 'Packets'
229
+ result [ 'Packets' ] . each do |pkt |
230
+ print_line pkt . inspect
231
+ end
232
+ end
233
+ print_line ( result [ 'error' ] . inspect ) if result . key? 'error'
234
+ result
235
+ end
236
+
166
237
#
167
238
# Sends TesterPresent packets as a background job
168
239
#
0 commit comments