blob: f0627c95bd07f397eabbca1c88cba1dbf9e3d9ce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/**
* @file
*
* @brief Backend API for USB-C malfunctioning device emulator
*/
#ifndef __EMUL_TCPCI_PARTNER_FAULTY_EXT_H
#define __EMUL_TCPCI_PARTNER_FAULTY_EXT_H
#include <zephyr/drivers/emul.h>
#include "emul/tcpc/emul_tcpci.h"
#include "emul/tcpc/emul_tcpci_partner_common.h"
#include "usb_pd.h"
/**
* @brief USB-C malfunctioning device extension backend API
* @defgroup tcpci_faulty_ext USB-C malfunctioning device extension
* @{
*
* USB-C malfunctioning device extension can be used with TCPCI partner
* emulator. It can be configured to not respond to source capability message
* (by not sending GoodCRC or Request after GoodCRC).
*/
/** Structure describing malfunctioning emulator data */
struct tcpci_faulty_ext_data {
struct tcpci_partner_extension ext;
/* List of action to perform */
struct k_fifo action_list;
};
/** Actions that can be performed by malfunctioning emulator */
enum tcpci_faulty_ext_action_type {
/**
* Fail to receive SourceCapabilities message. From TCPM point of view,
* GoodCRC message is not received.
*/
TCPCI_FAULTY_EXT_FAIL_SRC_CAP = BIT(0),
/**
* Ignore to respond to SourceCapabilities message with Request message.
* From TCPM point of view, GoodCRC message is received, but Request is
* missing.
*/
TCPCI_FAULTY_EXT_IGNORE_SRC_CAP = BIT(1),
/** Discard SourceCapabilities message and send Accept message */
TCPCI_FAULTY_EXT_DISCARD_SRC_CAP = BIT(2),
};
/** Structure to put in malfunctioning emulator action list */
struct tcpci_faulty_ext_action {
/* Reserved for FIFO */
void *fifo_reserved;
/* Actions that emulator should perform */
uint32_t action_mask;
/* Number of times to repeat action */
int count;
};
/* Count of actions which is treated by emulator as infinite */
#define TCPCI_FAULTY_EXT_INFINITE_ACTION 0
/**
* @brief Initialise USB-C malfunctioning device data structure
*
* @param data Pointer to USB-C malfunctioning device emulator data
* @param common_data Pointer to USB-C device emulator common data
* @param ext Pointer to next USB-C emulator extension
*
* @return Pointer to USB-C malfunctioning extension
*/
struct tcpci_partner_extension *
tcpci_faulty_ext_init(struct tcpci_faulty_ext_data *data,
struct tcpci_partner_data *common_data,
struct tcpci_partner_extension *ext);
/**
* @brief Add action to perform by USB-C malfunctioning extension
*
* @param data Pointer to USB-C malfunctioning device extension data
* @param action Non standard behavior to perform by emulator
*/
void tcpci_faulty_ext_append_action(struct tcpci_faulty_ext_data *data,
struct tcpci_faulty_ext_action *action);
/**
* @brief Clear all actions of USB-C malfunctioning extension
*
* @param data Pointer to USB-C malfunctioning device extension data
*/
void tcpci_faulty_ext_clear_actions_list(struct tcpci_faulty_ext_data *data);
/**
* @}
*/
#endif /* __EMUL_TCPCI_PARTNER_FAULTY_EXT_H */
|