dpdu_rust/
structures.rs

1use std::ffi::c_void;
2
3use crate::{PduIt, PduFilter, PduQueueMode, VidPreselectMode, CombinationMode, PduPt, PduPc, PduStatus, PduInfo, PduErrorEvt, PduCpst, TimingSet};
4
5
6#[repr(C)]
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
8/// Generic structure containing item type
9pub struct PduItem {
10    /// Item type
11    pub item_type: PduIt
12}
13
14#[repr(C)]
15#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
16/// Generic IOCTL type structure
17pub struct PduDataItem {
18    /// IOCTL Item type
19    pub item_type: PduIt,
20    /// IOCTL data structure pointer
21    pub p_data: *mut c_void
22}
23
24#[repr(C)]
25#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
26/// IOCTL programming voltage structure
27pub struct IoProgVoltageData {
28    /// Programming voltage (mV)
29    pub prog_voltage_mv: u32,
30    /// Pin number on connector
31    pub pin_on_dlc: u32
32}
33
34#[repr(C)]
35#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
36/// IOCTL Byte array structure
37pub struct IoByteArrayData {
38    /// Data size in bytes
39    pub data_size: u32,
40    /// Pointer to data
41    pub p_data: *mut u8 
42}
43
44impl From<&mut [u8]> for IoByteArrayData {
45    fn from(x: &mut [u8]) -> Self {
46        IoByteArrayData { data_size: x.len() as u32, p_data: x.as_mut_ptr() }
47    }
48}
49
50#[repr(C)]
51#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
52/// IOCTL Filter data structure
53/// 
54/// MASK & RAW == PATTERN
55pub struct IoFilterData {
56    /// Filter type
57    pub filter_type: PduFilter,
58    /// Filter number
59    pub filter_number: u32,
60    /// Compare size of the mask and pattern message
61    pub filter_compare_size: u32,
62    /// Mask message
63    pub filter_mask_msg: [u8; 12],
64    /// Pattern message
65    pub filter_pattern_msg: [u8; 12]
66}
67
68#[repr(C)]
69#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
70/// IOCTL Event queue property data
71pub struct IoEventQueuePropertyData {
72    /// Max size of the event queue
73    pub queue_size: u32,
74    /// Queue mode
75    pub queue_mode: PduQueueMode
76}
77
78#[repr(C)]
79#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
80/// IOCTL Vehicle ID request 
81pub struct VehicleIdRequest {
82    /// Preselection mode
83    pub preselection_mode: VidPreselectMode,
84    /// Preselection ASCII string
85    pub preselection_value: *mut u8,
86    /// Combination mode
87    pub combination_mode: CombinationMode,
88    /// discovery time in milliseconds
89    pub vehicle_discovery_time: u32,
90    /// Number of broadcast / multicast addresses found in [VehicleIdRequest::destination_addresses] array
91    pub num_destination_addresses: u32,
92    /// Pointer to array of IP addresses
93    pub destination_addresses: *mut IpAddrInfo
94}
95
96#[repr(C)]
97#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
98/// Address info
99pub struct IpAddrInfo {
100    /// IP version 4 = Ipv4, 6 = Ipv6
101    pub ip_version: u32,
102    /// Pointer to broadcast address (4 bytes for Ipv4, 16 bytes for Ipv6)
103    pub p_address: *mut u8
104}
105
106#[repr(C)]
107#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
108/// IOCTL ethernet switch state
109pub struct EthSwitchState {
110    /// Sense state - 0 = pin off, 1 = pin on
111    pub eth_sense_state: u32,
112    /// Pin number for ethernet activation
113    pub eth_act_pin_num: u32
114}
115
116#[repr(C)]
117#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
118/// Resource status data
119pub struct RscStatusData {
120    /// Item type
121    pub item_type: PduIt,
122    /// Number of entries
123    pub num_entries: u32,
124    /// Pointer to array of entries
125    pub p_resource_status_data: *mut RscStatusItem
126}
127
128#[repr(C)]
129#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
130/// Resource status item
131pub struct RscStatusItem {
132    /// MVCI handle ID
133    pub h_mod: u32,
134    /// Resource ID
135    pub resource_id: u32,
136    /// Resource information status
137    pub resource_status: u32
138}
139
140#[repr(C)]
141#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
142/// ComParam data information
143pub struct ParamItem {
144    /// Item type
145    pub item_type: PduIt,
146    /// Com param ID
147    pub com_param_id: u32,
148    /// Com param data type
149    pub com_param_data_type: PduPt,
150    /// Com param class type
151    pub com_param_class: PduPc,
152    /// Pointer to data of ComParam (of type specified in [ParamItem::com_param_class])
153    pub p_com_param_data: *mut c_void
154}
155
156#[repr(C)]
157#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
158/// Module identification information
159pub struct ModuleItem {
160    /// Item type
161    pub item_type: PduIt,
162    /// Number of entries in [ModuleItem::p_module_data]
163    pub num_entries: u32,
164    /// Pointer to array of [ModuleData]
165    pub p_module_data: *mut ModuleData
166}
167
168#[repr(C)]
169#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
170/// Module identification data
171pub struct ModuleData {
172    /// Module protocol type
173    pub module_type_id: u32,
174    /// Module handle ID
175    pub h_mod: u32,
176    /// Null terminated string of module name
177    pub vendor_module_name: *mut u8,
178    /// Null terminated string pointer of any additional info
179    pub vendor_additional_info: *mut u8,
180    /// Module status
181    pub status: PduStatus
182}
183
184#[repr(C)]
185#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
186/// Item resource identification item
187pub struct RscIdItem {
188    /// Item type
189    pub item_type: PduIt,
190    /// Number of entries in [RscIdItem::p_id_item_data]
191    pub num_modules: u32,
192    /// Pointer to array of [RscIdItemData]
193    pub p_id_item_data: *mut RscIdItemData
194}
195
196#[repr(C)]
197#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
198/// Item resource identification data
199pub struct RscIdItemData {
200    /// MVCI Handle ID
201    pub h_mod: u32,
202    /// Number of IDs
203    pub num_ids: u32,
204    /// Pointer to list of resource IDs
205    pub p_resource_id_array: *mut u32
206}
207
208#[repr(C)]
209#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
210/// Resource data
211pub struct RscData {
212    /// Bus type ID
213    pub bus_type_id: u32,
214    /// Protocol ID
215    pub protocol_id: u32,
216    /// Number of items in [RscData::p_dlc_pin_data]
217    pub num_pin_data: u32,
218    /// Pointer to array of [PinData]
219    pub p_dlc_pin_data: *mut PinData
220}
221
222#[repr(C)]
223#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
224/// Pin Data
225pub struct PinData {
226    /// Pin number on data connector
227    pub dlc_pin_number: u32,
228    /// Pin ID
229    pub dlc_pin_type_id: u32
230}
231
232#[repr(C)]
233#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
234/// Resource conflict item
235pub struct RscConflictItem {
236    /// Item type
237    pub item_type: PduIt,
238    /// Number of entries in [RscConflictItem::p_rsc_conflict_data]
239    pub num_entries: u32,
240    /// Pointer to array of [RscConflictData]
241    pub p_rsc_conflict_data: *mut RscConflictData
242}
243
244#[repr(C)]
245#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
246/// Resource conflict data
247pub struct RscConflictData {
248    /// MVCI handle ID with conflict
249    pub h_mod: u32,
250    /// The conflicting resource ID
251    pub resource_id: u32
252}
253
254#[repr(C)]
255#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
256/// Unique response identification data
257pub struct UniqueRespIdTableItem {
258    /// Item type
259    pub item_type: PduIt,
260    /// Number of entries in [UniqueRespIdTableItem::p_unique_data]
261    pub num_entries: u32,
262    /// Pointer to array of [EcuUniqueRespData]
263    pub p_unique_data: *mut EcuUniqueRespData
264}
265
266#[repr(C)]
267#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
268/// ECU Unique response data
269pub struct EcuUniqueRespData {
270    /// Unique response identifier
271    pub unique_resp_identifier: u32,
272    /// Number of ComParams for the unique identifier
273    pub num_param_items: u32,
274    /// Pointer to array of ComParams used to uniquely define the ECUs unique response
275    pub p_params: *mut ParamItem
276}
277
278#[repr(C)]
279#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
280/// Event notification item
281pub struct EventItem {
282    /// Item type
283    pub item_type: PduIt,
284    /// If from ComPrimitive, then this is the ComPrimitive handle, otherwise [PDU_HANDLE_UNDEF]
285    pub h_cop: u32,
286    /// ComPrimitive tag
287    pub p_cop_tag: *mut c_void,
288    /// Timestamp in microseconds
289    pub timestamp: u32,
290    /// Pointer to the data of the event
291    pub p_data: *mut c_void
292}
293
294#[repr(C)]
295#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
296/// Async event information data
297pub struct InfoData {
298    /// Information code
299    pub info_code: PduInfo,
300    /// optional extra information data
301    pub extra_info_data: u32
302}
303
304#[repr(C)]
305#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
306/// Async error notification data
307pub struct ErrorData {
308    /// Error code
309    pub error_code_id: PduErrorEvt,
310    /// optional extra error information
311    pub extra_error_info_id: u32
312}
313
314#[repr(C)]
315#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
316/// Async result notification
317pub struct ResultData {
318    /// Receive message status
319    pub rx_flag: FlagData,
320    /// ECU Response unique ID
321    pub unique_resp_identifier: u32,
322    /// Acceptance ID
323    pub acceptance_id: u32,
324    /// Timestamp indicator flag
325    pub timestamp_flags: FlagData,
326    /// Transmit message done in microseconds
327    pub tx_msg_done_timestamp: u32,
328    /// Start message timestamp in microseconds
329    pub start_msg_timestamp: u32,
330    /// Pointer to extra information
331    pub p_extra_info: *mut ExtraInfo,
332    /// Number of bytes in [ResultData::p_data_bytes]
333    pub num_data_bytes: u32,
334    /// Pointer to payload data structure
335    pub p_data_bytes: *mut u8
336}
337
338#[repr(C)]
339#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
340/// Extra information data
341pub struct ExtraInfo {
342    /// Number of bytes in [ExtraInfo::p_header_bytes]
343    pub num_header_bytes: u32,
344    /// Number of bytes in [ExtraInfo::p_footer_bytes]
345    pub num_footer_bytes: u32,
346    /// Reference to response header bytes
347    pub p_header_bytes: *mut u8,
348    /// Reference to response footer bytes
349    pub p_footer_bytes: *mut u8
350}
351
352#[repr(C)]
353#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
354/// Flag data
355pub struct FlagData {
356    /// Number of bytes in [FlagData::p_flag_data]
357    pub num_flag_bytes: u32,
358    /// Pointer to flag bytes
359    pub p_flag_data: *mut u8
360}
361
362#[repr(C)]
363#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
364/// Version information
365pub struct VersionData {
366    /// Release version of MVCI standard part 1 (Bit encoded)
367    pub mvci_part1_standard_version: u32,
368    /// Release version of MVCI standard part 2 (Bit encoded)
369    pub mvci_part2_standard_version: u32,
370    /// Hardware serial number from vendor
371    pub hw_serial_number: u32,
372    /// Hardware name
373    pub hw_name: [u8; 64],
374    /// Hardware version (Bit encoded)
375    pub hw_version: u32,
376    /// hardware date (Bit encoded)
377    pub hw_data: u32,
378    /// Type of MVCI module
379    pub hw_inferface: u32,
380    /// MVCI Firmware name
381    pub fw_name: [u8; 64],
382    /// MVCI firmware version (Bit encoded)
383    pub fw_version: u32,
384    /// MVCI firmware date (Bit encoded)
385    pub fw_date: u32,
386    /// MVCI vendor name
387    pub vendor_name: [u8; 64],
388    /// PDU API software name
389    pub pdu_api_sw_name: [u8; 64],
390    /// PDU API software version (Bit encoded)
391    pub pdu_api_sw_version: u32,
392    /// PDU API software date (Bit encoded)
393    pub pdi_api_sw_date: u32
394}
395
396#[repr(C)]
397#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
398/// Com primitive control data
399pub struct CopCtrlData {
400    /// Cycle time in milliseconds or delay time of the ComPrimitive
401    pub time: u32,
402    /// Number of send cycles. -1 for infinite
403    pub num_send_cycles: i32,
404    /// Number of receives. -1 for infinite
405    pub num_receive_cycles: i32,
406    /// Optional temporary setting for the ComPrimitive
407    pub temp_param_update: u32,
408    /// Transmit flag
409    pub tx_flag: FlagData,
410    /// Number of elements in [CopCtrlData::expected_response_array]
411    pub num_possible_expected_responses: u32,
412    /// Pointer to an array of expected responses
413    pub expected_response_array: *mut ExpRespData
414}
415
416#[repr(C)]
417#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
418/// DoIP IO Entity address data
419pub struct IoEntityAddressData {
420    /// Logical addresses 
421    pub logical_address: u32,
422    /// Timeout in milliseconds to wait for responses
423    pub doip_ctrl_timeout: u32
424}
425
426#[repr(C)]
427#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
428/// DoIP IO Entity status data
429pub struct IoEntityStatusData {
430    /// Type of DoIP entitiy
431    pub entity_type: u32,
432    /// Max number of Sockets allowed
433    pub tcp_clients_max: u32,
434    /// Number of current sockets
435    pub tcp_clients: u32,
436    /// Optional limit in bytes for max size of a single DoIP request
437    pub max_data_size: u32
438}
439
440#[repr(C)]
441#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
442/// Expected response structure
443pub struct ExpRespData {
444    /// Expected response type (0 = positive, 1 = negative)
445    pub response_type: u32,
446    /// ID assigned by application to be returned
447    pub acceptance_id: u32,
448    /// Number of bytes in [ExpRespData::p_mask_data] and [ExpRespData::p_pattern_data]
449    pub num_mask_pattern_bytes: u32,
450    /// Pointer to mask data
451    pub p_mask_data: *mut u8,
452    /// Pointer to pattern data
453    pub p_pattern_data: *mut u8,
454    /// Number of items in [ExpRespData::p_unique_resp_ids]
455    pub num_unique_resp_ids: u32,
456    /// Array containing unique response IDs
457    pub p_unique_resp_ids: *mut u32
458}
459
460#[repr(C)]
461#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
462/// ComParam byte field data
463pub struct ParamByteFieldData {
464    /// Maximum number of bytes the [ParamByteFieldData::p_data_array] can contain
465    pub param_max_len: u32,
466    /// Current (actual) number of bytes in [ParamByteFieldData::p_data_array]
467    pub param_act_len: u32,
468    /// Pointer to data array
469    pub p_data_array: *mut u8
470}
471
472#[repr(C)]
473#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
474/// ComParam struct field data
475pub struct ParamStructFieldData {
476    /// Struct type
477    pub com_param_struct_type: PduCpst,
478    /// Maximum number of structures the [ParamStructFieldData::p_struct_array] can contain
479    pub param_max_entries: u32,
480    /// Current (actual) number of structures in [ParamStructFieldData::p_struct_array]
481    pub param_act_entries: u32,
482    /// Pointer to structure array (See [ParamStructSessionTiming] and [ParamStructAccessTiming])
483    pub p_struct_array: *mut c_void
484}
485
486#[repr(C)]
487#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
488/// Session timing for [ParamStructFieldData] when [ParamStructFieldData::com_param_struct_type] is [PduCpst::SessionTiming]
489pub struct ParamStructSessionTiming {
490    /// Session ID
491    pub session: u16,
492    /// 1ms resolution
493    pub p2_max_high: u8,
494    /// 1ms resolution
495    pub p2_max_low: u8,
496    /// 10ms resolution
497    pub p2_star_high: u8,
498    /// 10ms resolution
499    pub p2_star_low: u8
500}
501
502#[repr(C)]
503#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
504/// Access timing for [ParamStructFieldData] when [ParamStructFieldData::com_param_struct_type] is [PduCpst::AccessTiming]
505pub struct ParamStructAccessTiming {
506    /// 0.5ms resolution - Minimum time between tester request and ECU response
507    pub p2_min: u8,
508    /// 0.5ms resolution - Maximum time between tester request and ECU response
509    pub p2_max: u8,
510    /// 250ms resolution - Minimum time between ECU response and start of new tester request
511    pub p3_min: u8,
512    /// 250ms resolution - Maximum time between ECU response and start of new tester request
513    pub p3_max: u8,
514    /// 0.5ms resolution - Minimum inter-byte time for tester request
515    pub p4_min: u8,
516    /// Timing set type
517    pub timing_set: TimingSet
518}
519
520#[repr(C)]
521#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
522/// Long field data
523pub struct ParamLongFieldData {
524    /// Maximum number of entries the [ParamLongFieldData::p_data_array] can contain
525    pub param_max_len: u32,
526    /// Current (actual) number of entries in [ParamLongFieldData::p_data_array]
527    pub param_act_len: u32,
528    /// Pointer to data array
529    pub p_data_array: *mut u32
530}