1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci#ifndef OHOS_HDI_USB_V1_1_USBD_PORT_H 17094332d3Sopenharmony_ci#define OHOS_HDI_USB_V1_1_USBD_PORT_H 18094332d3Sopenharmony_ci 19094332d3Sopenharmony_ci#include <fcntl.h> 20094332d3Sopenharmony_ci#include <sys/types.h> 21094332d3Sopenharmony_ci#include <unistd.h> 22094332d3Sopenharmony_ci 23094332d3Sopenharmony_ci#include "usbd.h" 24094332d3Sopenharmony_ci#include "v1_0/iusbd_subscriber.h" 25094332d3Sopenharmony_ci#include "v1_0/usb_types.h" 26094332d3Sopenharmony_ci 27094332d3Sopenharmony_ci#define DEFAULT_PORT_ID 1 28094332d3Sopenharmony_ci 29094332d3Sopenharmony_ci#define PORT_MODE_HOST_STR "host" 30094332d3Sopenharmony_ci#define PORT_MODE_DEVICE_STR "device" 31094332d3Sopenharmony_ci 32094332d3Sopenharmony_ci#define POWER_ROLE_NONE 0 33094332d3Sopenharmony_ci#define POWER_ROLE_SOURCE 1 34094332d3Sopenharmony_ci#define POWER_ROLE_SINK 2 35094332d3Sopenharmony_ci#define POWER_ROLE_MAX 3 36094332d3Sopenharmony_ci 37094332d3Sopenharmony_ci#define DATA_ROLE_NONE 0 38094332d3Sopenharmony_ci#define DATA_ROLE_HOST 1 39094332d3Sopenharmony_ci#define DATA_ROLE_DEVICE 2 40094332d3Sopenharmony_ci#define DATA_ROLE_MAX 3 41094332d3Sopenharmony_ci 42094332d3Sopenharmony_ci#define PORT_MODE_NONE 0 43094332d3Sopenharmony_ci#define PORT_MODE_DEVICE 1 44094332d3Sopenharmony_ci#define PORT_MODE_HOST 2 45094332d3Sopenharmony_ci 46094332d3Sopenharmony_ciusing OHOS::HDI::Usb::V1_1::PortInfo; 47094332d3Sopenharmony_ci 48094332d3Sopenharmony_ciusing OHOS::HDI::Usb::V1_1::IUsbdSubscriber; 49094332d3Sopenharmony_ci 50094332d3Sopenharmony_cinamespace OHOS { 51094332d3Sopenharmony_cinamespace HDI { 52094332d3Sopenharmony_cinamespace Usb { 53094332d3Sopenharmony_cinamespace V1_1 { 54094332d3Sopenharmony_ciclass UsbdPort { 55094332d3Sopenharmony_cipublic: 56094332d3Sopenharmony_ci static UsbdPort &GetInstance(); 57094332d3Sopenharmony_ci int32_t SetPort(int32_t portId, int32_t powerRole, int32_t dataRole, 58094332d3Sopenharmony_ci UsbdSubscriber *usbdSubscribers, uint32_t len); 59094332d3Sopenharmony_ci int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode); 60094332d3Sopenharmony_ci int32_t UpdatePort(int32_t mode, const sptr<HDI::Usb::V1_1::IUsbdSubscriber> &subscriber); 61094332d3Sopenharmony_ci void setPortPath(const std::string &path); 62094332d3Sopenharmony_ci 63094332d3Sopenharmony_ciprivate: 64094332d3Sopenharmony_ci UsbdPort() = default; 65094332d3Sopenharmony_ci ~UsbdPort() = default; 66094332d3Sopenharmony_ci UsbdPort(const UsbdPort &) = delete; 67094332d3Sopenharmony_ci UsbdPort(UsbdPort &&) = delete; 68094332d3Sopenharmony_ci UsbdPort &operator=(const UsbdPort &) = delete; 69094332d3Sopenharmony_ci UsbdPort &operator=(UsbdPort &&) = delete; 70094332d3Sopenharmony_ci 71094332d3Sopenharmony_ci int32_t IfCanSwitch(int32_t portId, int32_t powerRole, int32_t dataRole); 72094332d3Sopenharmony_ci int32_t OpenPortFile(int32_t flags); 73094332d3Sopenharmony_ci int32_t WritePortFile(int32_t powerRole, int32_t dataRole, int32_t mode); 74094332d3Sopenharmony_ci int32_t ReadPortFile(int32_t &powerRole, int32_t &dataRole, int32_t &mode); 75094332d3Sopenharmony_ci int32_t SetPortInit(int32_t portId, int32_t powerRole, int32_t dataRole); 76094332d3Sopenharmony_ci HDI::Usb::V1_1::PortInfo currentPortInfo_ = {DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE, PORT_MODE_DEVICE}; 77094332d3Sopenharmony_ci std::string path_; 78094332d3Sopenharmony_ci}; 79094332d3Sopenharmony_ci} // namespace V1_1 80094332d3Sopenharmony_ci} // namespace Usb 81094332d3Sopenharmony_ci} // namespace HDI 82094332d3Sopenharmony_ci} // namespace OHOS 83094332d3Sopenharmony_ci#endif // OHOS_HDI_USB_V1_1_USBD_PORT_H 84