### Global setting ###
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
SET(EXEC_PREFIX "\${prefix}")
-SET(LIBDIR "\${prefix}/lib")
+SET(LIBDIR ${LIB_INSTALL_DIR})
+SET(UNITDIR ${UNIT_INSTALL_DIR})
SET(INCLUDEDIR "\${prefix}/include")
SET(PKGCONFIGDIR "${PREFIX}/${LIB_INSTALL_DIR}/pkgconfig" CACHE PATH PKGCONFIGDIR)
SET(CMAKE_INSTALL_PREFIX "${PREFIX}")
INCLUDE(FindPkgConfig)
# Set required packages
-pkg_check_modules(pkgs REQUIRED glib-2.0 tcore dlog gudev-1.0)
+pkg_check_modules(pkgs REQUIRED glib-2.0 tcore dlog libudev)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ADD_DEFINITIONS("-DEXPORT_API=__attribute__((visibility(\"default\")))")
MESSAGE(${CMAKE_C_FLAGS})
-MESSAGE(${CMAKE_EXE_LINKER_FLAGS})
+MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
SET(SRCS
src/desc-dongleinterface.c
src/dongle_at.c
+ src/dongle_common.c
src/dongle_udev.c
)
SET_TARGET_PROPERTIES(dongleinterface-plugin PROPERTIES PREFIX "" OUTPUT_NAME dongleinterface-plugin)
# install
-INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${LIB_INSTALL_DIR}/telephony/plugins)
-INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME tel-plugin-dongleinterface)
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/packaging/telephony-dongle.service DESTINATION /usr/lib/systemd/system)
+INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${LIBDIR}/telephony/plugins)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION ${TZ_SYS_RO_SHARE}/license RENAME tel-plugin-dongleinterface)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/packaging/telephony-dongle.service DESTINATION ${UNITDIR})
#ifndef __DONGLE_AT_H__
#define __DONGLE_AT_H__
-#define PPPD_SCRIPT "/usr/sbin/pppd debug file /opt/etc/ppp/peers/provider"
+#include <tzplatform_config.h>
+
+#define PPPD_SCRIPT tzplatform_mkpath(TZ_SYS_SBIN, "pppd debug file /opt/etc/ppp/peers/provider")
#define MAX_PPP_RETRIES 30
-#define PPPD_DNS_PATH "/opt/etc/ppp/resolv.conf"
-#define PPPD_PID_PATH "/var/run/ppp0.pid"
+#define PPPD_DNS_PATH tzplatform_mkpath(TZ_SYS_ETC, "ppp/resolv.conf")
+#define PPPD_PID_PATH tzplatform_mkpath(TZ_SYS_RUN, "ppp0.pid")
#define CR '\r'
#define LF '\n'
gboolean _handle_at_ipc_init(TcoreHal *hal);
void _handle_at_ipc_deinit(TcoreHal *hal);
-gboolean _handle_at_add_uevent(TcoreHal *hal, GUdevDevice *parent_device);
+gboolean _handle_at_add_uevent(TcoreHal *hal, struct udev_device *parent_device);
TReturn _hal_setup_at_netif(CoreObject *co,
TcoreHalSetupNetifCallback func, void *user_data,
guint cid, gboolean enable);
--- /dev/null
+/*
+ * tel-plugin-dongleinterface
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * 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 __DONGLE_COMMON_H__
+#define __DONGLE_COMMON_H__
+
+#define TAB_SPACE " "
+
+void util_hex_dump(const char *pad, int size, const void *data);
+
+#endif /* __DONGLE_COMMON_H__ */
#ifndef __DONGLE_UDEV_H__
#define __DONGLE_UDEV_H__
-#include <gudev/gudev.h>
+#include <libudev.h>
__BEGIN_DECLS
typedef gboolean (*DongleUdevEnumerCallback)(DongleUdev *udev, GList *list,
void *user_data);
-typedef gboolean (*DongleUdevCallback)(DongleUdev *udev, GUdevDevice *device,
+typedef gboolean (*DongleUdevCallback)(DongleUdev *udev, struct udev_device *device,
void *user_data);
DongleUdev* dongle_udev_new(Server *s, const gchar **subsystems);
void dongle_udev_free(DongleUdev *udev);
Server* dongle_udev_ref_server(DongleUdev *udev);
-GUdevClient* dongle_udev_ref_client(DongleUdev *udev);
-GUdevEnumerator* dongle_udev_ref_enumerator(DongleUdev *udev);
+struct udev* dongle_udev_ref_client(DongleUdev *udev);
TReturn dongle_udev_add_enumerator_callback(DongleUdev *udev,
DongleUdevEnumerCallback func, void *user_data);
-GList* dongle_udev_exec_enumerator(DongleUdev *udev, gboolean event_emit_flag);
TReturn dongle_udev_add_callback(DongleUdev *udev, const char *subsystem,
const char *action, DongleUdevCallback func, void *user_data);
#define BUFFER_LEN_MAX 1024
/**< CP (Modem) Power ON Re-try options */
-#define CP_POWER_ON_TIMEOUT 10
+#define CP_POWER_ON_TIMEOUT 10000
#define MAX_CP_POWER_ON_RETRIES 10
#define DEVICE_NAME_LEN_MAX 16
Name: tel-plugin-dongleinterface
Summary: Dongle Interface plugin for CP interface
-Version: 0.2.24
+Version: 0.2.25
Release: 1
Group: Development/Libraries
License: Apache-2.0
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(tcore)
BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(gudev-1.0)
+BuildRequires: pkgconfig(libudev)
+BuildRequires: pkgconfig(libtzplatform-config)
Requires: ppp
Requires: usb-modeswitch
-# This package would be built only TV
-%if "%{?tizen_profile_name}" != "tv"
-ExcludeArch: %{arm} %ix86 x86_64
-%endif
-
-%if "%{?_repository}" == "emulator"
+%if "%{_with_emulator}" == "1"
ExcludeArch: %{arm} %ix86 x86_64
%endif
%setup -q
%build
-%cmake .
+%cmake . -DPRODUCT_TV=false -DUSB_POWER_SUPPLY=false \
+ -DCMAKE_INSTALL_PREFIX=%{_prefix} \
+ -DTZ_SYS_RO_SHARE=%TZ_SYS_RO_SHARE \
+ -DTZ_SYS_BIN=%TZ_SYS_BIN \
+ -DTZ_SYS_SBIN=%TZ_SYS_SBIN \
+ -DTZ_SYS_ETC=%TZ_SYS_ETC \
+ -DTZ_SYS_RUN=%TZ_SYS_RUN \
+ -DLIB_INSTALL_DIR=%{_libdir} \
+ -DUNIT_INSTALL_DIR=%{_unitdir}
+
make %{?jobs:-j%jobs}
%post
%install
rm -rf %{buildroot}
%make_install
-mkdir -p %{buildroot}/opt/etc/ppp
-mkdir -p %{buildroot}/usr/bin
-mkdir -p %{buildroot}/usr/share/license
-cp LICENSE %{buildroot}/usr/share/license/%{name}
-cp res/telephony_init.sh %{buildroot}/usr/bin/telephony_init.sh
-chmod 700 %{buildroot}/usr/bin/telephony_init.sh
+mkdir -p %{buildroot}%{TZ_SYS_ETC}/ppp
+mkdir -p %{buildroot}%{TZ_SYS_BIN}
+mkdir -p %{buildroot}%{TZ_SYS_RO_SHARE}/license
+cp LICENSE %{buildroot}%{TZ_SYS_RO_SHARE}/license/%{name}
+cp res/telephony_init.sh %{buildroot}%{TZ_SYS_BIN}/telephony_init.sh
+chmod 700 %{buildroot}%{TZ_SYS_BIN}/telephony_init.sh
+
+# DNS setting file
+touch %{buildroot}%{TZ_SYS_ETC}/resolv.conf
# Kernel module load for cellular dongle support
-mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants
-ln -s %{_libdir}/systemd/system/telephony-dongle.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/telephony-dongle.service
+mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants
+ln -s %{_unitdir}/telephony-dongle.service %{buildroot}%{_unitdir}/multi-user.target.wants/telephony-dongle.service
%files
%manifest tel-plugin-dongleinterface.manifest
%{_libdir}/telephony/plugins/*
/usr/share/license/%{name}
%attr(700,root,root) %{_bindir}/telephony_init.sh
+%attr(660,root,root) /opt/etc/resolv.conf
-%attr(644,root,root) %{_libdir}/systemd/system/telephony-dongle.service
-%attr(644,root,root) %{_libdir}/systemd/system/multi-user.target.wants/telephony-dongle.service
+%attr(644,root,root) %{_unitdir}/telephony-dongle.service
+%attr(644,root,root) %{_unitdir}/multi-user.target.wants/telephony-dongle.service
#include <signal.h>
#include <glib.h>
-#include <gudev/gudev.h>
+#include <libudev.h>
#include <tcore.h>
#include <server.h>
#include <user_request.h>
#include "dongleinterface.h"
+#include "dongle_common.h"
#include "dongle_at.h"
#include "dongle_udev.h"
TcoreHalSetupNetifCallback func, void *user_data,
guint cid, gboolean enable);
static gboolean __ipc_init(TcoreHal *hal);
-static gboolean _handle_add_uevent(DongleUdev *udev, GUdevDevice *device,
+static gboolean _handle_add_uevent(DongleUdev *udev, struct udev_device *device,
void *user_data);
static void __clear_pending_requests(TcoreHal *hal);
.setup_netif = __hal_setup_netif,
};
-static void __print_device_info(GUdevDevice *device)
+static void __print_device_info(struct udev_device *device)
{
- dbg("USB Device SysPath[%s]", g_udev_device_get_sysfs_path(device));
- dbg("USB Device Name[%s]", g_udev_device_get_name(device));
- dbg("USB Device Subsystem[%s]", g_udev_device_get_subsystem(device));
+ dbg("USB Device SysPath[%s]", udev_device_get_syspath(device));
+ dbg("USB Device Name[%s]", udev_device_get_sysname(device));
+ dbg("USB Device Subsystem[%s]", udev_device_get_subsystem(device));
}
static gboolean __ipc_init(TcoreHal *hal)
Server *s = (Server*)user_data;
TReturn ret = TCORE_RETURN_FAILURE;
+ dbg("Entry");
+
/* Send EXIT notification */
ret = tcore_server_send_notification(s, NULL, TNOTI_SERVER_EXIT, 0, NULL);
if (ret == TCORE_RETURN_FAILURE)
static enum tcore_hook_return __on__hal_send(TcoreHal *hal,
guint data_len, void *data, void *user_data)
{
- dbg("\n====== TX data DUMP ======\n");
+ dbg("====== TX data DUMP ======");
- dbg("\n====== TX data DUMP ======\n");
+ dbg("====== TX data DUMP ======");
return TCORE_HOOK_RETURN_CONTINUE;
}
static void __on_hal_recv(TcoreHal *hal,
guint data_len, const void *data, void *user_data)
{
- dbg("\n====== RX data DUMP ======\n");
+ dbg("====== RX data DUMP ======");
- dbg("\n====== RX data DUMP ======\n");
+ dbg("====== RX data DUMP ======");
}
static TReturn __hal_send(TcoreHal *hal, guint data_len, void *data)
return ret;
}
-static gboolean __get_device_vendor_id(GUdevDevice *parent_device,
+static gboolean __check_udev_device_vendor_id(struct udev_device *parent_device,
gchar *vendor_id)
{
const gchar *vid = NULL;
gboolean ret = FALSE;
if (parent_device)
- vid = g_udev_device_get_sysfs_attr(parent_device, "idVendor");
+ vid = udev_device_get_sysattr_value(parent_device, "idVendor");
if (vid) {
dbg("parent_device:[%p], vendor_id:[%s] ", parent_device, vid);
return ret;
}
-static gboolean __match_with_parent_device(GUdevDevice *device,
+static gboolean __match_with_parent_device(struct udev_device *device,
gchar const *device_path)
{
gboolean ret = FALSE;
dbg("Ignore this event!! udev device path is NULL.");
/* With some usb dongle,
- * g_udev_device_get_parent() function doesn't return
+ * udev_device_get_parent() function doesn't return
* valid parent device name in some time !!!
* (expected: '2-1' / return: 'usb2')
*
- * Instead of using g_udev_device_get_parent(),
+ * Instead of using udev_device_get_parent(),
* manually check parent device name from sysfs path. */
dbg("Stored device's parent: [%s]", device_path);
- sysfs_path = g_udev_device_get_sysfs_path(device);
+ sysfs_path = udev_device_get_syspath(device);
sysfs_tokens = g_strsplit(sysfs_path, "/", 0);
if (sysfs_tokens) {
token = sysfs_tokens[ptr++];
static gboolean __check_udev_subsystem_foreach(DongleUdev *udev,
const char **subsystems, void *user_data)
{
- GUdevEnumerator *enumerator;
- GUdevDevice *device;
- GUdevClient *client;
- GList *iter;
+ struct udev_enumerate *enumerator;
+ struct udev_device *device;
+ struct udev *client;
+ struct udev_list_entry *list_entry;
TcoreHal *hal;
gboolean found = FALSE;
int i = 0;
+ const char *syspath;
if (!udev) {
err("Udev is NULL");
client = dongle_udev_ref_client(udev);
if (!client) {
- err("GUdevClient is NULL");
+ err("udev is NULL");
return FALSE;
}
return FALSE;
}
- enumerator = g_udev_enumerator_new(client);
+ enumerator = udev_enumerate_new(client);
for (i = 0; subsystems[i]; i++)
- g_udev_enumerator_add_match_subsystem(enumerator, subsystems[i]);
+ udev_enumerate_add_match_subsystem(enumerator, subsystems[i]);
+
+ udev_enumerate_add_match_is_initialized(enumerator);
+ udev_enumerate_scan_devices(enumerator);
+
+ udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerator)) {
+
+ syspath = udev_list_entry_get_name(list_entry);
+ if (!syspath)
+ continue;
+
+ dbg("syspath = %s", syspath);
- g_udev_enumerator_add_match_is_initialized(enumerator);
- iter = g_udev_enumerator_execute(enumerator);
- while (iter) {
- device = (GUdevDevice *)(iter->data);
+ device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerator), syspath);
if (!device)
continue;
- if (g_str_has_prefix(g_udev_device_get_name(device), DEVICE_PREFIX)) {
+ if (g_str_has_prefix(udev_device_get_sysname(device), DEVICE_PREFIX)) {
dbg("Manually call udev handling function - tty device");
/* Manually call udev event function */
found = TRUE;
}
- g_object_unref(device);
- iter = g_list_next(iter);
+ udev_device_unref(device);
}
- g_list_free(iter);
- g_object_unref(enumerator);
+ udev_enumerate_unref(enumerator);
return found;
}
}
}
-static gboolean _handle_add_uevent(DongleUdev *udev, GUdevDevice *device,
+static gboolean _handle_add_uevent(DongleUdev *udev, struct udev_device *device,
void *user_data)
{
TcoreHal *hal = user_data;
TcorePlugin *plugin = tcore_hal_ref_plugin(hal);
PluginData *plugin_data = tcore_plugin_ref_user_data(plugin);
HalCustomData *custom_data = tcore_hal_ref_user_data(hal);
- GUdevDevice *parent_device = NULL;
+ struct udev_device *parent_device = NULL;
const gchar *parent_device_path = NULL;
const gchar *device_name = NULL;
gboolean res = FALSE;
dbg("plugin: [%p] plugin_data: [%p] hal: [%p] custom_data: [%p]",
plugin, plugin_data, hal, custom_data);
- device_name = g_udev_device_get_name(device);
+ device_name = udev_device_get_sysname(device);
if (custom_data->device_attached == TRUE) {
dbg("Ignore this event!! already attached!! [%s]", device_name);
}
/* Get parent device with subsystem of "usb" and devtype of "usb_device" */
- parent_device = g_udev_device_get_parent_with_subsystem(device, "usb",
- "usb_device");
+ parent_device = udev_device_get_parent_with_subsystem_devtype(device, "usb", "usb_device");
if (!parent_device) {
dbg("Ignore this event!! Parent device is not found. [%s]", device_name);
return TRUE;
}
- /* Get vendor ID */
- if (FALSE == __get_device_vendor_id(parent_device, custom_data->vendor_id)) {
- dbg("Ignore this event!! Failed to get vendor ID. [%s]", device_name);
+ /* Check vendor ID */
+ if (FALSE == __check_udev_device_vendor_id(parent_device, custom_data->vendor_id)) {
+ dbg("Ignore this event!! Vender ID is mismatched. [%s]", device_name);
return TRUE;
}
res = _handle_at_add_uevent(hal, parent_device);
if (res == FALSE) {
- g_object_unref(parent_device);
+ err("add_uevent failed");
return TRUE;
}
custom_data->device_info_counter = 0;
/* Set device information */
- parent_device_path = g_udev_device_get_name(parent_device);
+ parent_device_path = udev_device_get_sysname(parent_device);
dbg("Parent device name: [%s]", parent_device_path);
if (parent_device_path)
g_strlcpy(custom_data->device_path, parent_device_path,
PARENT_NAME_LEN_MAX);
custom_data->device_attached = TRUE;
- g_object_unref(parent_device);
/* Assign HAL to Core objects - update Mapping table */
tcore_server_add_cp_mapping_tbl_entry(plugin_data->modem,
return TRUE;
}
-static gboolean _on_remove_uevent(DongleUdev *udev, GUdevDevice *device,
+static gboolean _on_add_at_uevent(DongleUdev *udev, struct udev_device *device,
+ void *user_data)
+{
+ return _handle_add_uevent(udev, device, user_data);
+}
+
+static gboolean _on_remove_uevent(DongleUdev *udev, struct udev_device *device,
void *user_data)
{
TcoreHal *hal = user_data;
gchar *log_content = NULL;
gboolean res = FALSE;
GError *err = NULL;
+ char str[256] = {0, };
dbg("Entry");
/* Remove previous DNS setting to detect pppd activation */
dbg("Remove resolv.conf file");
- retval = system("/bin/rm -r "PPPD_DNS_PATH);
+ snprintf(str, 256, "/bin/rm -r %s", PPPD_DNS_PATH);
+ retval = system(str);
dbg("Remove result: %d", retval);
/* Close PPPD with pid file */
} else {
res = g_file_get_contents(PPPD_PID_PATH, &log_content, NULL, &err);
if (res && log_content) {
- int g_pppd_pid = atoi(log_content);
- if (0 == kill(g_pppd_pid, SIGTERM)) {
+ int g_pppd_pid = -1;
+
+ g_pppd_pid = atoi(log_content);
+ if (0 == kill(g_pppd_pid, SIGTERM))
dbg("Terminated PPPD PID [%d] !!!", g_pppd_pid);
- } else {
- err("Failure in terminating PPPD PID[%d] !!!", g_pppd_pid);
- }
+ else
+ dbg("Failure in terminating PPPD PID[%d] !!!", g_pppd_pid);
g_free(log_content);
} else {
+ dbg("Failed to get pppd pid");
err("Failed to get pppd pid [%s]", err->message);
g_error_free(err);
err = NULL;
{
Server *s;
const gchar *subsystem[] = {"tty", "net", NULL};
+ char str[256] = {0, };
PluginData *plugin_data;
TcoreHal *hal;
HalCustomData *custom_data;
dbg("Init!!!");
/* Remove previous DNS setting to detect pppd activation */
- retval = system("/bin/rm -r "PPPD_DNS_PATH);
+ snprintf(str, 256, "/bin/rm -r %s", PPPD_DNS_PATH);
+ retval = system(str);
dbg("Remove result: %d", retval);
if (!plugin) {
*/
dongle_udev_add_callback(custom_data->udev,
subsystem[0], "add",
- _handle_add_uevent, hal);
+ _on_add_at_uevent, hal);
dongle_udev_add_callback(custom_data->udev,
subsystem[0], "remove",
_on_remove_uevent, hal);
#include <signal.h>
#include <glib.h>
-#include <gudev/gudev.h>
+#include <libudev.h>
#include <tcore.h>
#include <server.h>
#include <hal.h>
#include <at.h>
#include <user_request.h>
+#include <tzplatform_config.h>
#include "dongleinterface.h"
#include "dongle_at.h"
+#include "dongle_common.h"
-#define PPPD_LOG "/opt/etc/ppp/logs/pppd.log"
-#define CHAT_CONNECT_LOG "/opt/etc/ppp/logs/chat.connect.log"
-#define CHAT_DISCONNECT_LOG "/opt/etc/ppp/logs/chat.disconnect.log"
+#define PPPD_LOG tzplatform_mkpath(TZ_SYS_ETC, "ppp/logs/pppd.log")
+#define CHAT_CONNECT_LOG tzplatform_mkpath(TZ_SYS_ETC, "ppp/logs/chat.connect.log")
+#define CHAT_DISCONNECT_LOG tzplatform_mkpath(TZ_SYS_ETC, "ppp/logs/chat.disconnect.log")
#define DONGLE_NAME_LEN_MAX 32
static gboolean __get_tty_devices(const char *parent_sysfs,
HalCustomData *custom_data)
{
- GUdevEnumerator *enumerator;
- GUdevDevice *device = NULL;
- GUdevClient *client = NULL;
- GList *iter, *device_list;
+ struct udev_enumerate *enumerator;
+ struct udev_device *device = NULL;
+ struct udev *client = NULL;
+ struct udev_list_entry *iter, *device_list;
const char *subsystem[] = {"usb-serial", NULL};
const char *device_name = NULL;
const char *device_sysfs = NULL;
return FALSE;
}
- client = g_udev_client_new(subsystem);
+ client = udev_new();
if (!client) {
err("Failed to create GUdevClient");
return FALSE;
}
- enumerator = g_udev_enumerator_new(client);
- g_udev_enumerator_add_match_subsystem(enumerator, "usb-serial");
- g_udev_enumerator_add_match_is_initialized(enumerator);
+ enumerator = udev_enumerate_new(client);
+ udev_enumerate_add_match_subsystem(enumerator, subsystem[0]);
+ udev_enumerate_scan_devices(enumerator);
+
+ device_list = udev_enumerate_get_list_entry(enumerator);
+
+ udev_list_entry_foreach(iter, device_list) {
+ device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerator),
+ udev_list_entry_get_name(iter));
+
+ device_name = udev_device_get_sysname(device);
+ device_sysfs = udev_device_get_syspath(device);
- device_list = g_udev_enumerator_execute(enumerator);
- for (iter = device_list; iter; iter = g_list_next(iter)) {
- device = (GUdevDevice *)(iter->data);
- device_name = g_udev_device_get_name(device);
- device_sysfs = g_udev_device_get_sysfs_path(device);
if (g_str_has_prefix(device_sysfs, parent_sysfs) == FALSE)
continue;
- dbg(" [#%d] SysPath[%s]", i, device_sysfs);
+ dbg(" [#%d] SysPath[%s]", i, device_sysfs);
if (strlen(found_modem_device) == 0
|| g_strcmp0(found_modem_device, device_name) > 0) {
/* Update modem device name */
snprintf(found_modem_device, DEVICE_NAME_LEN,
"%s", device_name);
- dbg(" [#%d] MODEM device", i);
+ dbg(" [#%d] MODEM device", i);
}
if (strlen(found_at_device) == 0
|| g_strcmp0(found_at_device, device_name) < 0) {
/* Update AT device name */
snprintf(found_at_device, DEVICE_NAME_LEN,
"%s", device_name);
- dbg(" [#%d] AT device", i);
+ dbg(" [#%d] AT device", i);
}
i++;
- g_object_unref(device);
+ udev_device_unref(device);
}
if (strlen(found_modem_device) == 0 || strlen(found_at_device) == 0) {
found_at_device);
OUT:
- g_list_free(device_list);
- g_object_unref(client);
- g_object_unref(enumerator);
+ udev_unref(client);
+ udev_enumerate_unref(enumerator);
return res;
}
/* Fetch device information over TTYUSB0 */
dev_path = g_strconcat(TTY_DEVICE_PATH, custom_data->modem_device, NULL);
dbg("modem device_name [%s]", custom_data->modem_device);
- tcore_util_hex_dump(" ", 20, (const void *)custom_data->modem_device);
+ util_hex_dump(" ", 20, (const void *)custom_data->modem_device);
ret = __send_at_command(dev_path, hal, __on_recv_ipc_message,
"AT+CGMI;+CGMM", TCORE_AT_MULTILINE,
__on_response_get_device_info,
}
}
-gboolean _handle_at_add_uevent(TcoreHal *hal, GUdevDevice *parent_device)
+gboolean _handle_at_add_uevent(TcoreHal *hal, struct udev_device *parent_device)
{
HalCustomData *custom_data = tcore_hal_ref_user_data(hal);
gboolean ret = FALSE;
}
/* Get tty devices name */
- ret = __get_tty_devices(g_udev_device_get_sysfs_path(parent_device),
+ ret = __get_tty_devices(udev_device_get_syspath(parent_device),
custom_data);
if (!ret)
err("Failed to get device name.");
err("[READ] recv_len: [%d] Error: [%s]", recv_len, buf);
return TRUE;
}
- dbg("\n [RECV] Length of received data: [%d] \n", recv_len);
+ dbg("[RECV] Len: [%d] data: [%s]", recv_len, recv_buffer);
- tcore_util_hex_dump(" ", recv_len, recv_buffer);
+ util_hex_dump(" ", recv_len, recv_buffer);
/* Emit response callback */
tcore_hal_emit_recv_callback(hal, recv_len, recv_buffer);
return TCORE_RETURN_FAILURE;
}
- dbg("Write - fd: [%d] len: [%d]", custom_data->fd, data_len);
+ dbg("Write - fd: [%d] len: [%d] data: [%s]", custom_data->fd, data_len, (guchar *) data);
ret = write(custom_data->fd, (guchar *) data, data_len);
if (ret < 0) {
TcoreHal *hal = tcore_object_get_hal(co);
HalCustomData *custom_data = tcore_hal_ref_user_data(hal);
int retval = 0;
+ char str[256] = {0, };
InterfaceData *data;
char ifname[DEVICE_NAME_LEN_MAX] = {0, };
gchar *command;
/* Enable PPPD daemon */
/* Redirect stdout / stderr to file */
- command = g_strdup_printf("%s %s &> " PPPD_LOG " &",
- PPPD_SCRIPT, custom_data->modem_device);
+ snprintf(str, 256, "%s", PPPD_LOG);
+ command = g_strdup_printf("%s %s &> %s &", PPPD_SCRIPT, custom_data->modem_device, str);
retval = system(command);
dbg("PPPD result: %d", retval);
sleep(1);
/* Remove previous DNS setting to detect pppd activation */
- retval = system("/bin/rm -r "PPPD_DNS_PATH);
+ snprintf(str, 256, "/bin/rm -r %s", PPPD_DNS_PATH);
+ retval = system(str);
dbg("Remove result: %d", retval);
/* Device name */
if (fp == NULL) {
if (device_attached == FALSE) {
FILE *pp = NULL;
+ char str[256] = {0, };
gchar *log_content = NULL;
gboolean res = FALSE;
GError *err = NULL;
}
/* Remove previous DNS setting to detect pppd activation */
- retval = system("/bin/rm -r "PPPD_DNS_PATH);
+ snprintf(str, 256, "/bin/rm -r %s", PPPD_DNS_PATH);
+ retval = system(str);
/* Stop timeout function */
if (iface_data->ppp_timeout_src)
--- /dev/null
+/*
+ * tel-plugin-dongleinterface
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <glib.h>
+
+#include <tcore.h>
+
+#include "dongle_common.h"
+
+void util_hex_dump(const char *pad, int size, const void *data)
+{
+ char buf[255] = {0, };
+ char hex[4] = {0, };
+ int i;
+ unsigned const char *p;
+
+ if (size <= 0) {
+ msg("%sno data", pad);
+ return;
+ }
+
+ p = (unsigned const char *) data;
+ snprintf(buf, 255, "%s%04X: ", pad, 0);
+ for (i = 0; i < size; i++) {
+ snprintf(hex, 4, "%02X ", p[i]);
+ strncat(buf, hex, strlen(hex));
+
+ if ((i + 1) % 8 == 0) {
+ if ((i + 1) % 16 == 0) {
+ msg("%s", buf);
+ memset(buf, 0, 255);
+ snprintf(buf, 255, "%s%04X: ", pad, i + 1);
+ } else {
+ strncat(buf, TAB_SPACE, strlen(TAB_SPACE));
+ }
+ }
+ }
+
+ msg("%s", buf);
+}
struct dongle_udev_type {
Server *server;
- GUdevClient *client;
- GUdevEnumerator *enumer;
+ struct udev *client;
+ struct udev_enumerate *enumer;
+ struct udev_monitor *mon;
+ guint udev_watch;
GSList *enumer_callbacks;
GSList *callbacks;
};
static const gchar *_default_subsystems[] = { NULL, };
-static void _on_uevent(GUdevClient *client, gchar *action, GUdevDevice *device,
- gpointer user_data)
+static gboolean on_udev_event(GIOChannel *channel, GIOCondition cond, gpointer user_data)
{
DongleUdev *udev = user_data;
GSList *cb = NULL;
struct udev_callback_type *node;
+ struct udev_device *device;
+ const char *subsystem, *action;
if (!udev)
- return;
+ return FALSE;
+
+ if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
+ err("Error with udev monitor channel");
+ udev->udev_watch = 0;
+ return FALSE;
+ }
+ device = udev_monitor_receive_device(udev->mon);
+ if (device == NULL)
+ return TRUE;
+
+ subsystem = udev_device_get_subsystem(device);
+ if (subsystem == NULL)
+ goto done;
+
+ action = udev_device_get_action(device);
+ if (action == NULL)
+ goto done;
- dbg("action = '%s'", action);
+ dbg("subsystem %s %s", subsystem, action);
for (cb = udev->callbacks; cb; cb = cb->next) {
node = cb->data;
if (node->subsystem)
if (g_strcmp0(node->subsystem,
- g_udev_device_get_subsystem(device)) != 0)
+ udev_device_get_subsystem(device)) != 0)
continue;
if (!node->func)
node->func(udev, device, node->user_data);
}
+
+
+ dbg("subsystem %s finished", subsystem);
+
+done:
+ udev_device_unref(device);
+ return TRUE;
}
+
DongleUdev *dongle_udev_new(Server *s, const gchar **subsystems)
{
- DongleUdev *udev;
+ DongleUdev *udev = NULL;
+ int fd = -1;
+ GIOChannel *channel = NULL;
udev = calloc(1, sizeof(struct dongle_udev_type));
- if (!udev)
- return NULL;
+ if (!udev) {
+ err("udev alloc failed");
+ goto OUT;
+ }
if (!subsystems)
subsystems = _default_subsystems;
udev->server = s;
- udev->client = g_udev_client_new(subsystems);
+ udev->client = udev_new();
+
+
if (!udev->client) {
- free(udev);
- return NULL;
+ err("udev_new() failed");
+ goto OUT;
}
- g_signal_connect(udev->client, "uevent", G_CALLBACK(_on_uevent), udev);
+ udev->mon = udev_monitor_new_from_netlink(udev->client, "udev");
+ if (!udev->mon) {
+ err("udevudev_monitor_new_from_netlink_new() failed");
+ goto OUT;
+ }
- udev->enumer = g_udev_enumerator_new(udev->client);
+ udev_monitor_filter_add_match_subsystem_devtype(udev->mon, "tty", NULL);
+ udev_monitor_filter_add_match_subsystem_devtype(udev->mon, "net", NULL);
+ udev_monitor_filter_update(udev->mon);
+
+ if (udev_monitor_enable_receiving(udev->mon) < 0) {
+ err("udev_monitor_enable_receiving() failed");
+ goto OUT;
+ }
+
+ udev->enumer = udev_enumerate_new(udev->client);
+ if (!udev->enumer) {
+ err("udevudev_monitor_new_from_netlink_new() failed");
+ goto OUT;
+ }
+
+ dbg("enumerate created succesufully");
+
+ udev_enumerate_add_match_subsystem(udev->enumer, subsystems[0]);
+ udev_enumerate_add_match_subsystem(udev->enumer, subsystems[1]);
+ udev_enumerate_scan_devices(udev->enumer);
+
+ fd = udev_monitor_get_fd(udev->mon);
+ channel = g_io_channel_unix_new(fd);
+ if (channel == NULL) {
+ err("g_io_channel_unix_new() failed");
+ goto OUT;
+ }
+
+ udev->udev_watch = g_io_add_watch(channel, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, on_udev_event, udev);
+ g_io_channel_unref(channel);
+
+
+ dbg("udev device created succesufully");
return udev;
+
+OUT:
+ if(udev) {
+ if(channel)
+ g_io_channel_unref(channel);
+
+ if (udev->client)
+ udev_unref(udev->client);
+
+ if (udev->enumer)
+ udev_enumerate_unref(udev->enumer);
+
+ if (udev->mon) {
+ udev_monitor_filter_remove(udev->mon);
+ udev_monitor_unref(udev->mon);
+ }
+ if (udev->udev_watch > 0)
+ g_source_remove(udev->udev_watch);
+ free(udev);
+ }
+ return NULL;
+
}
void dongle_udev_free(DongleUdev *udev)
return;
if (udev->client)
- g_object_unref(udev->client);
+ udev_unref(udev->client);
if (udev->enumer)
- g_object_unref(udev->enumer);
+ udev_enumerate_unref(udev->enumer);
+
+ if (udev->mon) {
+ udev_monitor_filter_remove(udev->mon);
+ udev_monitor_unref(udev->mon);
+ }
+
+ if (udev->udev_watch > 0)
+ g_source_remove(udev->udev_watch);
free(udev);
}
return udev->server;
}
-GUdevClient *dongle_udev_ref_client(DongleUdev *udev)
+struct udev *dongle_udev_ref_client(DongleUdev *udev)
{
if (!udev)
return NULL;
return udev->client;
}
-GUdevEnumerator *dongle_udev_ref_enumerator(DongleUdev *udev)
-{
- if (!udev)
- return NULL;
-
- return udev->enumer;
-}
-
TReturn dongle_udev_add_enumerator_callback(DongleUdev *udev,
DongleUdevEnumerCallback func, void *user_data)
{
return TCORE_RETURN_SUCCESS;
}
-GList *dongle_udev_exec_enumerator(DongleUdev *udev, gboolean event_emit_flag)
-{
- GList *list = NULL;
- GSList *cb = NULL;
- struct udev_enumer_callback_type *node;
-
- if (!udev)
- return NULL;
-
- list = g_udev_enumerator_execute(udev->enumer);
- if (!list)
- return NULL;
-
- if (event_emit_flag == FALSE)
- return list;
-
- for (cb = udev->enumer_callbacks; cb; cb = cb->next) {
- node = cb->data;
- if (!node)
- continue;
-
- if (!node->func)
- continue;
-
- node->func(udev, list, node->user_data);
- }
-
- return list;
-}
-
TReturn dongle_udev_add_callback(DongleUdev *udev, const char *subsystem,
const char *action, DongleUdevCallback func, void *user_data)
{