| 1 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* qmi-firmware-update -- Command line tool to update firmware in QMI devices |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* Copyright (C) 2016 Zodiac Inflight Innovations |
| 19 |
* Copyright (C) 2016-2022 Aleksander Morgado <[email protected]> |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "config.h" |
| 23 |
#include <stdlib.h> |
| 24 |
#include "qfu-helpers.h" |
| 25 |
|
| 26 |
/******************************************************************************/ |
| 27 |
|
| 28 |
static const gchar *device_type_str[] = { |
| 29 |
[QFU_HELPERS_DEVICE_TYPE_TTY] = "tty", |
| 30 |
[QFU_HELPERS_DEVICE_TYPE_CDC_WDM] = "cdc-wdm", |
| 31 |
}; |
| 32 |
|
| 33 |
G_STATIC_ASSERT (G_N_ELEMENTS (device_type_str) == QFU_HELPERS_DEVICE_TYPE_LAST); |
| 34 |
|
| 35 |
const gchar * |
| 36 |
qfu_helpers_device_type_to_string (QfuHelpersDeviceType type) |
| 37 |
{ |
| 38 |
return device_type_str[type]; |
| 39 |
} |
| 40 |
|
| 41 |
/******************************************************************************/ |
| 42 |
|
| 43 |
static const gchar *device_mode_str[] = { |
| 44 |
[QFU_HELPERS_DEVICE_MODE_UNKNOWN] = "unknown", |
| 45 |
[QFU_HELPERS_DEVICE_MODE_MODEM] = "modem", |
| 46 |
[QFU_HELPERS_DEVICE_MODE_DOWNLOAD] = "download", |
| 47 |
}; |
| 48 |
|
| 49 |
G_STATIC_ASSERT (G_N_ELEMENTS (device_mode_str) == QFU_HELPERS_DEVICE_MODE_LAST); |
| 50 |
|
| 51 |
const gchar * |
| 52 |
qfu_helpers_device_mode_to_string (QfuHelpersDeviceMode mode) |
| 53 |
{ |
| 54 |
return device_mode_str[mode]; |
| 55 |
} |
| 56 |
|
| 57 |
/******************************************************************************/ |
| 58 |
|
| 59 |
gchar * |
| 60 |
qfu_helpers_find_by_file_path (const gchar *path, |
| 61 |
GError **error) |
| 62 |
{ |
| 63 |
GFile *file; |
| 64 |
gchar *sysfs_path; |
| 65 |
|
| 66 |
file = g_file_new_for_path (path); |
| 67 |
sysfs_path = qfu_helpers_find_by_file (file, error); |
| 68 |
g_object_unref (file); |
| 69 |
return sysfs_path; |
| 70 |
} |
| 71 |
|
| 72 |
gchar * |
| 73 |
qfu_helpers_find_peer_port (const gchar *sysfs_path, |
| 74 |
GError **error) |
| 75 |
{ |
| 76 |
gchar *tmp, *path; |
| 77 |
|
| 78 |
tmp = g_build_filename (sysfs_path, "port", "peer", NULL); |
| 79 |
path = realpath (tmp, NULL); |
| 80 |
g_free (tmp); |
| 81 |
if (!path) |
| 82 |
return NULL; |
| 83 |
|
| 84 |
g_debug ("[qfu-helpers] peer port for '%s' found: %s", sysfs_path, path); |
| 85 |
return path; |
| 86 |
} |