Skip to main content

dpdu_api_types/
structures.rs

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