From 017f151ea36a3309aec05ace79916ab3dae35ac1 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Fri, 2 Jan 2015 09:57:45 -0800 Subject: pd: reject getSourceCap/getSinkCap if doesn't apply Send a reject to getSourceCap if device is only a Sink. Send a reject to getSinkCap if device is only a Source. BUG=chrome-os-partner:34979 BRANCH=samus TEST=make -j buildall Change-Id: I53711fd88235c1c98d40fa2c59d48306e9ee7ba2 Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/238231 Reviewed-by: Vincent Palatin --- common/usb_pd_protocol.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 788ce9755a..4ae13bd127 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -585,7 +585,14 @@ static int send_source_cap(int port) const uint32_t *src_pdo = pd_src_pdo; const int src_pdo_cnt = pd_src_pdo_cnt; #endif - uint16_t header = PD_HEADER(PD_DATA_SOURCE_CAP, pd[port].power_role, + uint16_t header; + + if (src_pdo_cnt == 0) + /* No source capabilities defined, sink only */ + header = PD_HEADER(PD_CTRL_REJECT, pd[port].power_role, + pd[port].data_role, pd[port].msg_id, 0); + else + header = PD_HEADER(PD_DATA_SOURCE_CAP, pd[port].power_role, pd[port].data_role, pd[port].msg_id, src_pdo_cnt); bit_len = send_validate_message(port, header, src_pdo_cnt, src_pdo); @@ -993,10 +1000,14 @@ static void handle_ctrl_request(int port, uint16_t head, (pd[port].task_state == PD_STATE_SRC_DISCOVERY)) set_state(port, PD_STATE_SRC_NEGOCIATE); break; -#ifdef CONFIG_USB_PD_DUAL_ROLE case PD_CTRL_GET_SINK_CAP: +#ifdef CONFIG_USB_PD_DUAL_ROLE send_sink_cap(port); +#else + send_control(port, PD_CTRL_REJECT); +#endif break; +#ifdef CONFIG_USB_PD_DUAL_ROLE case PD_CTRL_GOTO_MIN: break; case PD_CTRL_PS_RDY: -- cgit v1.2.1