summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoungjae Cho <y0.cho@samsung.com>2022-04-05 22:35:11 -0700
committerYoungjae Cho <y0.cho@samsung.com>2022-04-13 09:41:10 +0900
commitf6fc8860b9878ea2d54171bd311d6fe3a26defa1 (patch)
tree75101928efb2aad25645a50f19294badf2666340
parent7b56a0e892d1aa53f2ac690fee32353815781f9b (diff)
downloaddevice-f6fc8860b9878ea2d54171bd311d6fe3a26defa1.tar.gz
device-f6fc8860b9878ea2d54171bd311d6fe3a26defa1.tar.bz2
device-f6fc8860b9878ea2d54171bd311d6fe3a26defa1.zip
usb-gadget: move usb-gadget to deviced
Change-Id: Ic967ad1db398355627d33a206a9a1d2ec81ad49b Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
-rw-r--r--include/backend/hal-usb_gadget-interface.h135
-rw-r--r--include/hal-usb_gadget.h36
-rw-r--r--src/usb_gadget.c177
3 files changed, 0 insertions, 348 deletions
diff --git a/include/backend/hal-usb_gadget-interface.h b/include/backend/hal-usb_gadget-interface.h
deleted file mode 100644
index 6db0156..0000000
--- a/include/backend/hal-usb_gadget-interface.h
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __HAL_USB_GADGET_INTERFACE_H__
-#define __HAL_USB_GADGET_INTERFACE_H__
-
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*The default USB configuration */
-#define DEFAULT_VID 0x04e8
-#define DEFAULT_PID 0x6860
-#define DEFAULT_BCD_DEVICE 0x0100
-
-#define DEFAULT_LANG 0x409 /* US_en */
-#define DEFAULT_MANUFACTURER "Samsung"
-#define DEFAULT_PRODUCT "TIZEN"
-#define DEFAULT_SERIAL "01234TEST"
-
-#define DEFAULT_BMATTRIBUTES ((1 << 7) | (1 << 6))
-#define DEFAULT_MAX_POWER 500
-
-typedef enum {
- USB_FUNCTION_IDX_MTP = 0,
- USB_FUNCTION_IDX_ACM = 1,
- USB_FUNCTION_IDX_SDB = 2,
- USB_FUNCTION_IDX_RNDIS = 3,
- USB_FUNCTION_IDX_DIAG = 4,
- USB_FUNCTION_IDX_CONN_GADGET = 5,
- USB_FUNCTION_IDX_DM = 6,
- USB_FUNCTION_IDX_RMNET = 7,
- USB_FUNCTION_IDX_MAX = USB_FUNCTION_IDX_RMNET + 1
-} usb_function_idx_e;
-
-typedef enum {
- USB_FUNCTION_NONE = 0,
- USB_FUNCTION_MTP = 1 << USB_FUNCTION_IDX_MTP,
- USB_FUNCTION_ACM = 1 << USB_FUNCTION_IDX_ACM,
- USB_FUNCTION_SDB = 1 << USB_FUNCTION_IDX_SDB,
- USB_FUNCTION_RNDIS = 1 << USB_FUNCTION_IDX_RNDIS,
- USB_FUNCTION_DIAG = 1 << USB_FUNCTION_IDX_DIAG,
- USB_FUNCTION_CONN_GADGET = 1 << USB_FUNCTION_IDX_CONN_GADGET,
- USB_FUNCTION_DM = 1 << USB_FUNCTION_IDX_DM,
- USB_FUNCTION_RMNET = 1 << USB_FUNCTION_IDX_RMNET
-} usb_function_e;
-
-struct usb_function {
- int id;
- const char *name;
- const char *instance;
-
- int is_functionfs;
- const char *service;
-
- /* do not stop the service on disabling usb-gadget function */
- int remain_after_disable;
-
- void (*handler)(int enable);
-};
-
-struct usb_configuration_attributes {
- uint8_t bmAttributs;
- int MaxPower;
-};
-
-struct usb_configuration_strings {
- uint16_t lang_code;
- char *config_str;
-};
-
-struct usb_configuration {
- struct usb_configuration_attributes attrs;
- struct usb_configuration_strings strs;
- struct usb_function **funcs;
-};
-
-struct usb_gadget_attrs {
- uint8_t bDeviceClass;
- uint8_t bDeviceSubClass;
- uint8_t bDeviceProtocol;
- uint16_t idVendor;
- uint16_t idProduct;
- uint16_t bcdDevice;
-};
-
-struct usb_gadget_strings {
- uint16_t lang_code;
- char *manufacturer;
- char *product;
- char *serial;
-};
-
-struct usb_gadget {
- struct usb_gadget_attrs attrs;
- struct usb_gadget_strings strs;
- struct usb_configuration **configs;
-};
-
-struct usb_gadget_id {
- unsigned int function_mask;
-};
-
-/////////////////////////////////////////////////////////////////////////////////////////
-typedef struct _hal_backend_usb_gadget_funcs {
- char *board_serial;
-
- int (*id_to_gadget)(struct usb_gadget_id *gadget_id, char *serial, struct usb_gadget **gadget);
- void (*cleanup_gadget)(struct usb_gadget *gadget);
-
- int (*enable)(void);
- int (*disable)(void);
- int (*reconfigure_gadget)(struct usb_gadget *gadget);
-} hal_backend_usb_gadget_funcs;
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* __HAL_BOARD_INTERFACE_H__ */
diff --git a/include/hal-usb_gadget.h b/include/hal-usb_gadget.h
deleted file mode 100644
index 590fa9a..0000000
--- a/include/hal-usb_gadget.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef __HAL_USB_GADGET_H__
-#define __HAL_USB_GADGET_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int hal_device_usb_gadget_get_backend(void);
-int hal_device_usb_gadget_put_backend(void);
-int hal_device_usb_gadget_enable(void);
-int hal_device_usb_gadget_disable(void);
-int hal_device_usb_gadget_change_mode(unsigned mode);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* __HAL_BOARD_H__ */
diff --git a/src/usb_gadget.c b/src/usb_gadget.c
deleted file mode 100644
index da3537d..0000000
--- a/src/usb_gadget.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <hal/hal-common.h>
-
-#include "common.h"
-#include "hal-board.h"
-#include "hal-usb_gadget-interface.h"
-
-#define SERIAL_MAX 128
-
-static hal_backend_usb_gadget_funcs *hal_usb_gadget_funcs;
-/*
--1 : failed to initialize
-0 : not initialized
-1 : succeeded to initialize
-*/
-static int hal_initialized = 0;
-
-static int usb_gadget_is_valid(hal_backend_usb_gadget_funcs *usb_gadget_funcs)
-{
- if(usb_gadget_funcs &&
- usb_gadget_funcs->board_serial &&
- usb_gadget_funcs->id_to_gadget &&
- usb_gadget_funcs->cleanup_gadget &&
- usb_gadget_funcs->enable &&
- usb_gadget_funcs->disable &&
- usb_gadget_funcs->reconfigure_gadget)
- return 1;
-
- return 0;
-}
-
-static int get_board_serial(hal_backend_usb_gadget_funcs *usb_gadget_funcs)
-{
- char board_serial[SERIAL_MAX] = {0, };
- int retval;
-
- if (!usb_gadget_funcs)
- return -EINVAL;
-
- retval = hal_device_board_get_device_serial_number(board_serial, SERIAL_MAX);
- if (retval == 0) {
- usb_gadget_funcs->board_serial = strndup(board_serial, SERIAL_MAX);
- } else {
- _E("Failed to get board serial for USB, use default serial=%s", DEFAULT_SERIAL);
- usb_gadget_funcs->board_serial = strndup(DEFAULT_SERIAL, SERIAL_MAX);
- }
-
- if (!usb_gadget_funcs->board_serial)
- return -ENOMEM;
-
- return 0;
-}
-
-int hal_device_usb_gadget_get_backend(void)
-{
- int ret;
-
- if (hal_usb_gadget_funcs)
- return 0;
-
- ret = hal_common_get_backend(HAL_MODULE_DEVICE_USB_GADGET, (void **)&hal_usb_gadget_funcs);
- if (ret < 0) {
- _E("Failed to get USB gadget backend");
- hal_initialized = -1;
- return -EINVAL;
- }
-
- (void) get_board_serial(hal_usb_gadget_funcs);
-
- if(!usb_gadget_is_valid(hal_usb_gadget_funcs)) {
- _E("USB gadget backend is not valid");
- hal_common_put_backend(HAL_MODULE_DEVICE_USB_GADGET, (void *)hal_usb_gadget_funcs);
- hal_initialized = -1;
- return -ENODEV;
- }
-
- hal_initialized = 1;
- return 0;
-}
-
-int hal_device_usb_gadget_put_backend(void)
-{
- if (!hal_usb_gadget_funcs)
- return 0;
-
- if(!usb_gadget_is_valid(hal_usb_gadget_funcs))
- return -ENODEV;
-
- hal_common_put_backend(HAL_MODULE_DEVICE_USB_GADGET, (void *)hal_usb_gadget_funcs);
-
- free(hal_usb_gadget_funcs->board_serial);
- hal_usb_gadget_funcs = NULL;
- hal_initialized = 0;
-
- return 0;
-}
-
-int hal_device_usb_gadget_enable(void)
-{
- int ret;
-
- if (!hal_usb_gadget_funcs && !hal_initialized) {
- if ((ret = hal_device_usb_gadget_get_backend()) < 0)
- return ret;
- }
-
- if(!usb_gadget_is_valid(hal_usb_gadget_funcs))
- return -ENODEV;
-
- return hal_usb_gadget_funcs->enable();
-}
-
-int hal_device_usb_gadget_disable(void)
-{
- int ret;
-
- if (!hal_usb_gadget_funcs && !hal_initialized) {
- if ((ret = hal_device_usb_gadget_get_backend()) < 0)
- return ret;
- }
-
- if(!usb_gadget_is_valid(hal_usb_gadget_funcs))
- return -ENODEV;
-
- return hal_usb_gadget_funcs->disable();
-}
-
-int hal_device_usb_gadget_change_mode(unsigned mode)
-{
- int ret;
- struct usb_gadget *gadget;
- struct usb_gadget_id gadget_id;
-
- if (!hal_usb_gadget_funcs && !hal_initialized) {
- if ((ret = hal_device_usb_gadget_get_backend()) < 0)
- return ret;
- }
-
- if(!usb_gadget_is_valid(hal_usb_gadget_funcs))
- return -ENODEV;
-
- memset(&gadget_id, 0, sizeof(gadget_id));
- gadget_id.function_mask = mode;
-
- ret = hal_usb_gadget_funcs->id_to_gadget(&gadget_id, hal_usb_gadget_funcs->board_serial, &gadget);
- if (ret) {
- _E("Unable to translate USB mode id into gadget: %d", ret);
- return ret;
- }
-
- ret = hal_usb_gadget_funcs->reconfigure_gadget(gadget);
- hal_usb_gadget_funcs->cleanup_gadget(gadget);
- if (ret) {
- _E("Unable to configure USB gadget: %d", ret);
- return ret;
- }
-
- return 0;
-}
-