When dpm policy about usb is received, the target has to take actions according to the policy.
1. Allow
The host can access to the target via usb and the user can see the storage of it
2. Disallow
The host cannot access to the target via usb, so the user cannot see the contents of storage
Change-Id: I32918269d3ddb41cac948c36d73cb4ad741d32dc
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
Signed-off-by: Hyotaek Shim <hyotaek.shim@samsung.com>
#include "core/common.h"
#include "core/devices.h"
#include "core/edbus-handler.h"
+#include "extcon/extcon.h"
#define CONTROL_HANDLER_NAME "control"
#define CONTROL_GETTER_NAME "getcontrol"
const char *name;
} devices[] = {
/* Add id & ops to provide start/stop control */
- { DEVICE_CONTROL_MMC, "mmc" },
- { DEVICE_CONTROL_USBCLIENT, "usbclient" },
- { DEVICE_CONTROL_BLOCK, "block" },
+ { DEVICE_CONTROL_MMC, "mmc" },
+ { DEVICE_CONTROL_USBCLIENT, "USB" },
+ { DEVICE_CONTROL_BLOCK, "block" },
};
static int control_handler(int argc, char **argv)
if (i >= ARRAY_SIZE(devices))
return -EINVAL;
- FIND_DEVICE_INT(dev_ops, devices[i].name);
+
+ FIND_DEVICE(dev_ops, devices[i].name);
+ if (!check_default(dev_ops)) {
+ _I("Device %s found", devices[i].name);
if (enable)
ret = device_start(dev_ops);
else
ret = device_stop(dev_ops);
+ } else {
+ if (enable)
+ ret = extcon_enable_device(devices[i].name);
+ else
+ ret = extcon_disable_device(devices[i].name);
+ }
return ret;
}
#define EXTCON_PATH "/sys/class/extcon"
#define STATE_NAME "STATE"
+#define METHOD_SYSPOPUP_SHOW "show"
+
#define BUF_MAX 256
static dd_list *extcon_list;
if (!dev)
return -ENOENT;
+ if (!dev->enabled)
+ return -ENODEV;
+
return dev->status;
}
static int extcon_update(const char *name, const char *value)
{
struct extcon_ops *dev;
+ char *param[1];
+ char buf[BUF_MAX];
int status;
+ int ret = 0;
if (!name || !value)
return -EINVAL;
_I("Changed %s device : %d -> %d", name, dev->status, status);
dev->status = status;
+
+ if (dev->enabled == false && strncmp(name, "USB", strlen("USB")) == 0) {
+ if (status > 0) {
+ snprintf(buf, BUF_MAX, "usb-client");
+ param[0] = buf;
+ ret = dbus_method_sync(DEVICEMANAGER_BUS_NAME, DEVICEMANAGER_PATH_POPUP,
+ DEVICEMANAGER_INTERFACE_POPUP, METHOD_SYSPOPUP_SHOW, "s", param);
+ if (ret < 0)
+ _E("Failed to launch USB restricted popup(%d)", ret);
+ return ret;
+ } else
+ return 0;
+ }
+
if (dev->update)
dev->update(status);
return 0;
}
+int extcon_enable_device(const char *name)
+{
+ struct extcon_ops *dev;
+ int ret;
+
+ dev = find_extcon(name);
+ if (!dev)
+ return -ENODEV;
+
+ if (dev->enabled) {
+ _I("extcon(%s) already enabled", name);
+ return 0;
+ }
+
+ dev->init(NULL);
+ dev->enabled = true;
+
+ if (strncmp(name, "USB", strlen("USB")) == 0) {
+ ret = extcon_update("USB", "0");
+ if (ret != 0)
+ _E("fail to disconnect USB");
+
+ ret = extcon_update("USB", "1");
+ if (ret != 0)
+ _E("fail to connect USB");
+ }
+ _I("extcon(%s) enabled", name);
+
+ return 0;
+}
+
+int extcon_disable_device(const char *name)
+{
+ struct extcon_ops *dev;
+ char *param[1];
+ char buf[BUF_MAX];
+ int ret;
+
+ dev = find_extcon(name);
+ if (!dev)
+ return -ENODEV;
+
+ snprintf(buf, BUF_MAX, "usb-client");
+ param[0] = buf;
+ ret = dbus_method_sync(DEVICEMANAGER_BUS_NAME, DEVICEMANAGER_PATH_POPUP,
+ DEVICEMANAGER_INTERFACE_POPUP, METHOD_SYSPOPUP_SHOW, "s", param);
+ if (ret < 0)
+ _E("Failed to launch USB restricted popup(%d)", ret);
+
+ if (!dev->enabled) {
+ _I("extcon(%s) already disabled", name);
+ return 0;
+ }
+
+ dev->exit(NULL);
+ dev->enabled = false;
+
+ _I("extcon(%s) disabled", name);
+
+ return 0;
+}
+
static int extcon_parsing_value(const char *value)
{
char *s, *p;
_I("[extcon] init (%s)", dev->name);
if (dev->init)
dev->init(data);
+ dev->enabled = true;
}
event_handler_state_changed((void *)&state);
_I("[extcon] deinit (%s)", dev->name);
if (dev->exit)
dev->exit(data);
+ dev->enabled = false;
}
}
struct extcon_ops {
const char *name;
int status;
+ int enabled;
void (*init)(void *data);
void (*exit)(void *data);
int (*update)(int status);
void remove_extcon(struct extcon_ops *dev);
int extcon_get_status(const char *name);
-
+int extcon_enable_device(const char *name);
+int extcon_disable_device(const char *name);
#endif /* __EXTCON_H__ */
DBusMessage *reply;
DBusError err;
int ret, result;
+ dbus_bool_t result_bool;
conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
if (!conn) {
if (!reply) {
_E("dbus_connection_send error(%s:%s) %s %s:%s-%s",
err.name, err.message, dest, path, interface, method);
- dbus_error_free(&err);
+
+ if (dbus_error_is_set(&err))
+ dbus_error_free(&err);
+
return -ECOMM;
}
ret = dbus_message_get_args(reply, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
- dbus_message_unref(reply);
if (!ret) {
- _E("no message : [%s:%s] %s %s:%s-%s",
- err.name, err.message, dest, path, interface, method);
- dbus_error_free(&err);
- return -ENOMSG;
+ if (dbus_error_is_set(&err))
+ dbus_error_free(&err);
+
+ dbus_error_init(&err);
+ ret = dbus_message_get_args(reply, &err, DBUS_TYPE_BOOLEAN, &result_bool, DBUS_TYPE_INVALID);
+ if (!ret) {
+ _E("no message : [%s:%s] %s %s:%s-%s",
+ err.name, err.message, dest, path, interface, method);
+
+ if (dbus_error_is_set(&err))
+ dbus_error_free(&err);
+
+ result = -ENOMSG;
+ } else {
+ result = (int)result_bool;
+ }
}
+ dbus_message_unref(reply);
return result;
}
#define CRASHD_PATH_CRASH CRASHD_OBJECT_PATH"/Crash"
#define CRASHD_INTERFACE_CRASH CRASHD_INTERFACE_NAME".Crash"
+/*
+ * Device Manager Policy Popup
+ */
+#define DEVICEMANAGER_BUS_NAME "org.tizen.DevicePolicyManager"
+#define DEVICEMANAGER_OBJECT_PATH "/org/tizen/DevicePolicyManager"
+#define DEVICEMANAGER_INTERFACE_NAME DEVICEMANAGER_BUS_NAME
+
+#define DEVICEMANAGER_PATH_POPUP DEVICEMANAGER_OBJECT_PATH"/Syspopup"
+#define DEVICEMANAGER_INTERFACE_POPUP DEVICEMANAGER_INTERFACE_NAME".Syspopup"
/***************************************************************/
static void usb_release()
{
- if (usb_client)
+ if (usb_client) {
if (usb_client->common.info->close)
usb_client->common.info->close(&usb_client->common);
+ usb_client = NULL;
+ }
- if (gadget_translator)
+ if (gadget_translator) {
if (gadget_translator->common.info->close)
gadget_translator->common.info->close(
&gadget_translator->common);
+ gadget_translator = NULL;
+ }
}
static int usb_config_init(void)