├── .editorconfig ├── .gitignore ├── .gitlab-ci.yml ├── AUTHORS ├── LICENSES ├── GPL-2.0-or-later.txt └── LGPL-2.1-or-later.txt ├── NEWS ├── README.md ├── RELEASING ├── build-aux ├── mbim-codegen │ ├── Message.py │ ├── ObjectList.py │ ├── Struct.py │ ├── mbim-codegen │ └── utils.py ├── mbim-mkenums └── templates │ ├── mbim-enum-types.c.template │ ├── mbim-enum-types.h.template │ ├── mbim-error-quarks.c.template │ ├── mbim-error-types.c.template │ ├── mbim-error-types.h.template │ ├── mbim-flag-types.c.template │ └── mbim-flag-types.h.template ├── data ├── mbim-service-atds.json ├── mbim-service-auth.json ├── mbim-service-basic-connect.json ├── mbim-service-compal.json ├── mbim-service-dss.json ├── mbim-service-fibocom.json ├── mbim-service-google.json ├── mbim-service-intel-at-tunnel.json ├── mbim-service-intel-firmware-update-v2.json ├── mbim-service-intel-firmware-update.json ├── mbim-service-intel-mutual-authentication.json ├── mbim-service-intel-thermal-rf.json ├── mbim-service-intel-tools.json ├── mbim-service-ms-basic-connect-extensions-v2.json ├── mbim-service-ms-basic-connect-extensions-v3.json ├── mbim-service-ms-basic-connect-extensions.json ├── mbim-service-ms-basic-connect-v2.json ├── mbim-service-ms-basic-connect-v3.json ├── mbim-service-ms-firmware-id.json ├── mbim-service-ms-host-shutdown.json ├── mbim-service-ms-sar.json ├── mbim-service-ms-uicc-low-level-access.json ├── mbim-service-ms-voice-extensions.json ├── mbim-service-phonebook.json ├── mbim-service-proxy-control.json ├── mbim-service-qdu.json ├── mbim-service-qmi.json ├── mbim-service-quectel.json ├── mbim-service-sms.json ├── mbim-service-stk.json └── mbim-service-ussd.json ├── docs ├── libmbim-icon.svg ├── libmbim-logo.png ├── libmbim-logo.svg ├── man │ └── meson.build └── reference │ └── libmbim-glib │ ├── libmbim-glib-common.sections │ ├── libmbim-glib-docs.xml │ ├── meson.build │ ├── version.xml.in │ └── xml │ ├── gtkdocentities.ent.in │ └── meson.build ├── examples ├── simple-tester-c │ ├── README │ ├── meson.build │ └── simple-tester-c.c └── simple-tester-python │ ├── README │ └── simple-tester-python ├── meson.build ├── meson_options.txt ├── src ├── common │ ├── mbim-common.c │ ├── mbim-common.h │ ├── meson.build │ └── test │ │ ├── meson.build │ │ └── test-common.c ├── libmbim-glib │ ├── 76-mbim-device-ownership.rules.in │ ├── generated │ │ └── meson.build │ ├── kernel │ │ ├── if_link.h │ │ └── wwan.h │ ├── libmbim-glib.h │ ├── mbim-cid.c │ ├── mbim-cid.h │ ├── mbim-compat.c │ ├── mbim-compat.h │ ├── mbim-device.c │ ├── mbim-device.h │ ├── mbim-enums.h │ ├── mbim-errors.h │ ├── mbim-helpers-netlink.c │ ├── mbim-helpers-netlink.h │ ├── mbim-helpers.c │ ├── mbim-helpers.h │ ├── mbim-message-private.h │ ├── mbim-message.c │ ├── mbim-message.h │ ├── mbim-net-port-manager-wdm.c │ ├── mbim-net-port-manager-wdm.h │ ├── mbim-net-port-manager-wwan.c │ ├── mbim-net-port-manager-wwan.h │ ├── mbim-net-port-manager.c │ ├── mbim-net-port-manager.h │ ├── mbim-proxy-helpers.c │ ├── mbim-proxy-helpers.h │ ├── mbim-proxy.c │ ├── mbim-proxy.h │ ├── mbim-tlv-private.h │ ├── mbim-tlv.c │ ├── mbim-tlv.h │ ├── mbim-utils.c │ ├── mbim-utils.h │ ├── mbim-uuid.c │ ├── mbim-uuid.h │ ├── mbim-version.h.in │ ├── meson.build │ ├── symbol.map │ └── test │ │ ├── meson.build │ │ ├── test-cid.c │ │ ├── test-fragment.c │ │ ├── test-message-builder.c │ │ ├── test-message-fuzzer-samples.c │ │ ├── test-message-fuzzer.c │ │ ├── test-message-parser.c │ │ ├── test-message.c │ │ ├── test-proxy-helpers.c │ │ └── test-uuid.c ├── mbim-proxy │ ├── mbim-proxy.c │ └── meson.build ├── mbimcli │ ├── mbimcli │ ├── mbimcli-atds.c │ ├── mbimcli-basic-connect.c │ ├── mbimcli-compal.c │ ├── mbimcli-dss.c │ ├── mbimcli-fibocom.c │ ├── mbimcli-google.c │ ├── mbimcli-helpers-quectel.c │ ├── mbimcli-helpers-quectel.h │ ├── mbimcli-helpers.c │ ├── mbimcli-helpers.h │ ├── mbimcli-intel-at-tunnel.c │ ├── mbimcli-intel-firmware-update.c │ ├── mbimcli-intel-mutual-authentication.c │ ├── mbimcli-intel-thermal-rf.c │ ├── mbimcli-intel-tools.c │ ├── mbimcli-link-management.c │ ├── mbimcli-ms-basic-connect-extensions.c │ ├── mbimcli-ms-firmware-id.c │ ├── mbimcli-ms-host-shutdown.c │ ├── mbimcli-ms-sar.c │ ├── mbimcli-ms-uicc-low-level-access.c │ ├── mbimcli-ms-voice-extensions.c │ ├── mbimcli-phonebook.c │ ├── mbimcli-quectel.c │ ├── mbimcli-sms.c │ ├── mbimcli.c │ ├── mbimcli.h │ ├── meson.build │ └── tests │ │ ├── meson.build │ │ └── test-quectel.c └── meson.build └── utils ├── mbim-network.in └── meson.build /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | trim_trailing_whitespace = true 6 | insert_final_newline = true 7 | 8 | [{*.c,*.h}] 9 | indent_style = space 10 | indent_size = 4 11 | tab_width = 4 12 | 13 | [meson.build] 14 | indent_size = 2 15 | indent_style = space 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.bz2 3 | *.pyc 4 | tags 5 | /.vscode 6 | /cscope.out 7 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | include: 2 | - project: freedesktop/ci-templates 3 | ref: 290b79e0e78eab67a83766f4e9691be554fc4afd 4 | file: 5 | - templates/ubuntu.yml 6 | 7 | stages: 8 | - container prep 9 | - precheck 10 | - build 11 | 12 | .common_variables: 13 | variables: 14 | FDO_UPSTREAM_REPO: mobile-broadband/libmbim 15 | FDO_DISTRIBUTION_VERSION: '20.04' 16 | FDO_DISTRIBUTION_TAG: '2021-11-05.1' 17 | FDO_DISTRIBUTION_PACKAGES: ca-certificates git gcc libgirepository1.0-dev 18 | libglib2.0-dev gtk-doc-tools libglib2.0-doc 19 | gobject-introspection bash-completion valac 20 | meson ninja-build help2man 21 | 22 | build container: 23 | extends: 24 | - .fdo.container-build@ubuntu 25 | - .common_variables 26 | stage: container prep 27 | only: 28 | - main 29 | - merge_requests 30 | - tags 31 | - schedules 32 | 33 | verify-dco: 34 | stage: precheck 35 | extends: 36 | - .fdo.distribution-image@ubuntu 37 | - .common_variables 38 | only: 39 | - merge_requests 40 | script: | 41 | if [[ -n "${CI_MERGE_REQUEST_DIFF_BASE_SHA}" ]]; then 42 | export COMMITS=$(git log --no-merges --format="%H" ${CI_MERGE_REQUEST_DIFF_BASE_SHA}.. | xargs) 43 | for c in ${COMMITS}; do 44 | $(git log --format="%b" -1 ${c} | grep -q "^Signed-off-by: .* <.*@.*>") && rc="$?" || rc="$?" 45 | if [[ $rc -ne 0 ]]; then 46 | echo "Commit ${c} failed DCO Signed-off-by check" 47 | exit $rc 48 | fi 49 | done 50 | fi 51 | 52 | build-no-introspection: 53 | stage: build 54 | extends: 55 | - .fdo.distribution-image@ubuntu 56 | - .common_variables 57 | only: 58 | - main 59 | - merge_requests 60 | - tags 61 | - schedules 62 | script: 63 | - meson setup build --prefix=/usr -Dwerror=true -Dintrospection=false 64 | - ninja -C build 65 | - ninja -C build install 66 | 67 | build-debug: 68 | stage: build 69 | extends: 70 | - .fdo.distribution-image@ubuntu 71 | - .common_variables 72 | only: 73 | - main 74 | - merge_requests 75 | - tags 76 | - schedules 77 | script: 78 | - meson setup build --buildtype=debug --prefix=/usr -Dgtk_doc=true -Dwerror=true 79 | - ninja -C build 80 | - ninja -C build install 81 | - ninja -C build dist 82 | - ninja -C build uninstall 83 | 84 | build-no-deprecated: 85 | stage: build 86 | extends: 87 | - .fdo.distribution-image@ubuntu 88 | - .common_variables 89 | only: 90 | - main 91 | - merge_requests 92 | - tags 93 | - schedules 94 | script: 95 | - CFLAGS="-DMBIM_DISABLE_DEPRECATED" meson setup build --prefix=/usr -Dwerror=true -Dintrospection=false 96 | - ninja -C build 97 | - ninja -C build install 98 | 99 | build-release: 100 | stage: build 101 | extends: 102 | - .fdo.distribution-image@ubuntu 103 | - .common_variables 104 | only: 105 | - main 106 | - merge_requests 107 | - tags 108 | - schedules 109 | script: 110 | - meson setup build --buildtype=release --prefix=/usr -Dgtk_doc=true -Dwerror=true 111 | - ninja -C build 112 | - ninja -C build install 113 | - ninja -C build dist 114 | - ninja -C build uninstall 115 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Current maintainers: 2 | Aleksander Morgado 3 | Dan Williams 4 | 5 | Other contributors: 6 | Ben Chan 7 | Iñigo Martínez 8 | Som_SP 9 | som 10 | Yegor Yefremov 11 | Greg Suarez 12 | Bjørn Mork 13 | Daniele Palmas 14 | Eric Caruso 15 | Roshan Pius 16 | ZhangMingjie 17 | Ivan Mikhanchuk 18 | lywpljw 19 | Emil Ljungdahl 20 | Lubomir Rintel 21 | Prathmesh Prabhu 22 | Shawn J. Goff 23 | diekleinekuh 24 | Arnaud Desmier 25 | Boris Egorov 26 | Carlo Lobrano 27 | Christof Meerwald 28 | Collin McMillan 29 | David Ward 30 | Jack Song 31 | Jaroslav Stepanek 32 | King.Sun 33 | Marius B. Kotsbak 34 | Michal Mazur 35 | Nicolas Cavallari 36 | Philip Withnall 37 | Raju 38 | Scott Lee 39 | Shih-Yuan Lee (FourDollars) 40 | Yunlian Jiang 41 | goapunk 42 | ljw 43 | lvmaorui 44 | maorui lv 45 | wicadmin 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | # libmbim 8 | 9 | libmbim is a glib-based library for talking to WWAN modems and devices which 10 | speak the Mobile Broadband Interface Model (MBIM) protocol. 11 | 12 | ## Documentation 13 | 14 | Project documentation is kept in: 15 | https://modemmanager.org/docs/libmbim/ 16 | 17 | ## License 18 | 19 | * `libmbim-glib` library is released under the LGPL-2.1-or-later license. 20 | * `mbimcli` and `mbim-network` tools are released under the GPL-2.0-or-later license. 21 | 22 | License texts can be found under the `LICENSES` folder. 23 | 24 | ## Code of Conduct 25 | 26 | Please note that this project is released with a Contributor Code of Conduct. 27 | By participating in this project you agree to abide by its terms, which you can 28 | find in the following link: 29 | https://www.freedesktop.org/wiki/CodeOfConduct 30 | CoC issues may be raised to the project maintainers at the following address: 31 | libmbim-devel-owner@lists.freedesktop.org 32 | -------------------------------------------------------------------------------- /RELEASING: -------------------------------------------------------------------------------- 1 | 2 | The libmbim releases are generated using meson. 3 | 4 | 1) For major releases: 5 | * Increment mbim_minor_version and reset mbim_micro_version. 6 | * Assuming API/ABI compatibility, increment both current and age. 7 | 8 | 2) For stable branch releases: 9 | * Increment mbim_micro_version. 10 | 11 | 3) Bump 'version' in meson.build (eg, to "1.28.0") 12 | 13 | 4) Configure and build the whole project, making sure gtk-doc and introspection 14 | are enabled: 15 | $ meson setup build \ 16 | --prefix=/usr \ 17 | --buildtype=release \ 18 | -Dintrospection=true \ 19 | -Dgtk_doc=true 20 | $ ninja -C build 21 | 22 | 5) Run the test suite and install locally: 23 | $ ninja -C build dist 24 | $ sudo ninja -C build install 25 | 26 | 6) Push changes to a release MR on gitlab; once CI passes merge the PR. 27 | 28 | 7) Add signed tag pointing to the merge commit for the release MR: 29 | $ git tag -s 1.28.0 30 | 31 | The description included in the signed tag could be: 32 | Release 1.28.0 33 | 34 | 8) Create directories for the manpages and gtk-doc documentation in 35 | freedesktop.org, and also update the 'latest' links: 36 | $ ssh fd.o 37 | [fd.o] $ cd ${libmbim}/man/ 38 | [fd.o] $ rm latest 39 | [fd.o] $ mkdir -p ${VERSION} 40 | [fd.o] $ ln -s ${VERSION} latest 41 | [fd.o] $ cd ${libmbim}/libmbim-glib/ 42 | [fd.o] $ rm latest 43 | [fd.o] $ mkdir -p ${VERSION} 44 | [fd.o] $ ln -s ${VERSION} latest 45 | 46 | 9) Generate HTML for the manpages: 47 | $ roffit < build/docs/man/mbimcli.1 > mbimcli.1.html 48 | $ roffit < build/docs/man/mbim-network.1 > mbim-network.1.html 49 | 50 | 10) Upload manpages in HTML to freedesktop.org: 51 | $ scp *.1.html fd.o:${libmbim}/man/${VERSION}/ 52 | 53 | 11) Copy documentation from /usr/share/gtk-doc and fix online references manually 54 | $ mkdir html 55 | $ cp -r /usr/share/gtk-doc/html/libmbim-glib/* html/ 56 | $ for FILE in $(ls html/*.html); do \ 57 | sed -i 's|]* href="\.\./glib/[^"]*| 7 | # 8 | # Implementation originally developed in 'libqmi'. 9 | # 10 | 11 | import string 12 | import re 13 | 14 | """ 15 | Add the common copyright header to the given file 16 | """ 17 | def add_copyright(f): 18 | f.write( 19 | "\n" 20 | "/* GENERATED CODE... DO NOT EDIT */\n" 21 | "\n" 22 | "/* SPDX-License-Identifier: LGPL-2.1-or-later */\n" 23 | "/*\n" 24 | " * Copyright (C) 2013 - 2018 Aleksander Morgado \n" 25 | " */\n" 26 | "\n"); 27 | 28 | 29 | """ 30 | Build a header guard string based on the given filename 31 | """ 32 | def build_header_guard(output_name): 33 | return "__LIBMBIM_GLIB_" + output_name.replace('-', '_').upper() + "__" 34 | 35 | """ 36 | Write the common header start chunk 37 | """ 38 | def add_header_start(f, output_name): 39 | translations = { 'guard' : build_header_guard(output_name) } 40 | template = ( 41 | "\n" 42 | "#include \n" 43 | "#include \n" 44 | "#include \n" 45 | "\n" 46 | "#include \"mbim-message.h\"\n" 47 | "#include \"mbim-device.h\"\n" 48 | "#include \"mbim-enums.h\"\n" 49 | "#include \"mbim-tlv.h\"\n" 50 | "\n" 51 | "#ifndef ${guard}\n" 52 | "#define ${guard}\n" 53 | "\n" 54 | "G_BEGIN_DECLS\n") 55 | f.write(string.Template(template).substitute(translations)) 56 | 57 | 58 | """ 59 | Write the header documentation sections 60 | """ 61 | def add_header_sections(f, input_name): 62 | translations = { 'section_name' : "mbim-" + remove_prefix(input_name,"mbim-service-"), 63 | 'service_name' : string.capwords(remove_prefix(input_name,"mbim-service-").replace('-', ' ')) } 64 | template = ( 65 | "\n" 66 | "/**\n" 67 | " * SECTION:${section_name}\n" 68 | " * @title: ${service_name} service\n" 69 | " * @short_description: Support for the ${service_name} service.\n" 70 | " *\n" 71 | " * This section implements support for requests, responses and notifications in the\n" 72 | " * ${service_name} service.\n" 73 | " */\n") 74 | f.write(string.Template(template).substitute(translations)) 75 | 76 | 77 | """ 78 | Write the common header stop chunk 79 | """ 80 | def add_header_stop(f, output_name): 81 | template = string.Template ( 82 | "\n" 83 | "G_END_DECLS\n" 84 | "\n" 85 | "#endif /* ${guard} */\n") 86 | f.write(template.substitute(guard = build_header_guard(output_name))) 87 | 88 | 89 | """ 90 | Write the common source file start chunk 91 | """ 92 | def add_source_start(f, output_name): 93 | template = string.Template ( 94 | "\n" 95 | "#include \n" 96 | "\n" 97 | "#include \"${name}.h\"\n" 98 | "#include \"mbim-message-private.h\"\n" 99 | "#include \"mbim-tlv-private.h\"\n" 100 | "#include \"mbim-enum-types.h\"\n" 101 | "#include \"mbim-flag-types.h\"\n" 102 | "#include \"mbim-error-types.h\"\n" 103 | "#include \"mbim-device.h\"\n" 104 | "#include \"mbim-utils.h\"\n") 105 | f.write(template.substitute(name = output_name)) 106 | 107 | 108 | """ 109 | Write a separator comment in the file 110 | """ 111 | def add_separator(f, separator_type, separator_name): 112 | template = string.Template ( 113 | "\n" 114 | "/*****************************************************************************/\n" 115 | "/* ${type}: ${name} */\n") 116 | f.write(template.substitute(type = separator_type, 117 | name = separator_name)) 118 | 119 | 120 | """ 121 | Build an underscore name from the given full name 122 | e.g.: "This is a message" --> "this_is_a_message" 123 | """ 124 | def build_underscore_name(name): 125 | return name.replace(' ', '_').replace('-', '_').lower() 126 | 127 | 128 | """ 129 | Build an underscore uppercase name from the given full name 130 | e.g.: "This is a message" --> "THIS_IS_A_MESSAGE" 131 | """ 132 | def build_underscore_uppercase_name(name): 133 | return name.replace(' ', '_').replace('-', '_').upper() 134 | 135 | 136 | 137 | """ 138 | Build an underscore name from the given camelcase name 139 | e.g.: "ThisIsAMessage" --> "this_is_a_message" 140 | """ 141 | def build_underscore_name_from_camelcase(camelcase): 142 | s0 = camelcase.replace('IP','Ip') 143 | s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', s0) 144 | return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() 145 | 146 | 147 | 148 | """ 149 | Build a camelcase name from the given full name 150 | e.g.: "This is a message" --> "ThisIsAMessage" 151 | """ 152 | def build_camelcase_name(name): 153 | return string.capwords(name).replace(' ', '') 154 | 155 | 156 | """ 157 | Build a dashed lowercase name from the given full name 158 | e.g.: "This is a message" --> "this-is-a-message" 159 | """ 160 | def build_dashed_name(name): 161 | return name.lower().replace(' ', '-') 162 | 163 | 164 | """ 165 | Remove the given prefix from the string 166 | """ 167 | def remove_prefix(line, prefix): 168 | return line[len(prefix):] if line.startswith(prefix) else line 169 | 170 | 171 | """ 172 | Read the contents of the JSON file, skipping lines prefixed with '//', which are 173 | considered comments. 174 | """ 175 | def read_json_file(path): 176 | f = open(path) 177 | out = '' 178 | for line in f.readlines(): 179 | stripped = line.strip() 180 | if stripped.startswith('//'): 181 | # Skip this line 182 | # We add an empty line instead so that errors when parsing the JSON 183 | # report the proper line number 184 | out += "\n" 185 | else: 186 | out += line 187 | return out 188 | 189 | """ 190 | Compare two version strings given in MAJOR.MINOR format. 191 | Just to avoid needing to include e.g. packaging.version.parse just for this 192 | """ 193 | def version_compare(v1,v2): 194 | major_v1 = int(v1.partition(".")[0]) 195 | major_v2 = int(v2.partition(".")[0]) 196 | if major_v2 > major_v1: 197 | return 1 198 | if major_v2 < major_v1: 199 | return -1 200 | # major_v2 == major_v1 201 | minor_v1 = int(v1.partition(".")[2]) 202 | minor_v2 = int(v2.partition(".")[2]) 203 | if minor_v2 > minor_v1: 204 | return 1 205 | if minor_v2 < minor_v1: 206 | return -1 207 | # minor_v2 == minor_v1 208 | return 0 209 | -------------------------------------------------------------------------------- /build-aux/templates/mbim-enum-types.c.template: -------------------------------------------------------------------------------- 1 | /*** BEGIN file-header ***/ 2 | 3 | /*** END file-header ***/ 4 | 5 | /*** BEGIN file-production ***/ 6 | /* enumerations from "@filename@" */ 7 | /*** END file-production ***/ 8 | 9 | /*** BEGIN value-header ***/ 10 | static const G@Type@Value @enum_name@_values[] = { 11 | /*** END value-header ***/ 12 | /*** BEGIN value-production ***/ 13 | { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, 14 | /*** END value-production ***/ 15 | /*** BEGIN value-tail ***/ 16 | { 0, NULL, NULL } 17 | }; 18 | 19 | /* Define type-specific symbols */ 20 | 21 | GType 22 | @enum_name@_get_type (void) 23 | { 24 | static gsize g_define_type_id_initialized = 0; 25 | 26 | if (g_once_init_enter (&g_define_type_id_initialized)) { 27 | GType g_define_type_id = 28 | g_@type@_register_static (g_intern_static_string ("@EnumName@"), 29 | @enum_name@_values); 30 | g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); 31 | } 32 | 33 | return g_define_type_id_initialized; 34 | } 35 | 36 | /* Enum-specific method to get the value as a string. 37 | * We get the nick of the GEnumValue. Note that this will be 38 | * valid even if the GEnumClass is not referenced anywhere. */ 39 | const gchar * 40 | @enum_name@_get_string (@EnumName@ val) 41 | { 42 | guint i; 43 | 44 | for (i = 0; @enum_name@_values[i].value_nick; i++) { 45 | if ((gint)val == @enum_name@_values[i].value) 46 | return @enum_name@_values[i].value_nick; 47 | } 48 | 49 | return NULL; 50 | } 51 | 52 | /*** END value-tail ***/ 53 | 54 | /*** BEGIN file-tail ***/ 55 | /*** END file-tail ***/ 56 | -------------------------------------------------------------------------------- /build-aux/templates/mbim-enum-types.h.template: -------------------------------------------------------------------------------- 1 | /*** BEGIN file-header ***/ 2 | 3 | #include 4 | 5 | G_BEGIN_DECLS 6 | /*** END file-header ***/ 7 | 8 | /*** BEGIN file-production ***/ 9 | 10 | /* enumerations from "@filename@" */ 11 | /*** END file-production ***/ 12 | 13 | /*** BEGIN value-header ***/ 14 | GType @enum_name@_get_type (void) G_GNUC_CONST; 15 | #define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) 16 | 17 | /* Define type-specific symbols */ 18 | #define __@ENUMNAME@_IS_@TYPE@__ 19 | 20 | /** 21 | * @enum_name@_get_string: 22 | * @val: a @EnumName@. 23 | * 24 | * Gets the nickname string for the #@EnumName@ specified at @val. 25 | * 26 | * Returns: (transfer none): a string with the nickname, or %NULL if not found. Do not free the returned value. 27 | * 28 | * Since: @enumsince@ 29 | */ 30 | const gchar *@enum_name@_get_string (@EnumName@ val); 31 | 32 | /*** END value-header ***/ 33 | 34 | /*** BEGIN file-tail ***/ 35 | G_END_DECLS 36 | 37 | /*** END file-tail ***/ 38 | -------------------------------------------------------------------------------- /build-aux/templates/mbim-error-quarks.c.template: -------------------------------------------------------------------------------- 1 | /*** BEGIN file-header ***/ 2 | 3 | #include 4 | 5 | /*** END file-header ***/ 6 | 7 | /*** BEGIN file-production ***/ 8 | /* enumerations from "@filename@" */ 9 | /*** END file-production ***/ 10 | 11 | /*** BEGIN value-header ***/ 12 | 13 | #define ERROR_PREFIX @ENUMNAME@_DBUS_PREFIX 14 | static const GDBusErrorEntry @enum_name@_entries[] = { 15 | /*** END value-header ***/ 16 | 17 | /*** BEGIN value-production ***/ 18 | { @VALUENAME@, ERROR_PREFIX ".@valuenick@" }, 19 | /*** END value-production ***/ 20 | 21 | /*** BEGIN value-tail ***/ 22 | }; 23 | #undef ERROR_PREFIX 24 | 25 | GQuark 26 | @enum_name@_quark (void) 27 | { 28 | static volatile gsize quark_volatile = 0; 29 | 30 | if (!quark_volatile) 31 | g_dbus_error_register_error_domain ("@enum_name@_quark", 32 | &quark_volatile, 33 | @enum_name@_entries, 34 | G_N_ELEMENTS (@enum_name@_entries)); 35 | 36 | return (GQuark) quark_volatile; 37 | } 38 | 39 | /*** END value-tail ***/ 40 | 41 | /*** BEGIN file-tail ***/ 42 | /*** END file-tail ***/ 43 | -------------------------------------------------------------------------------- /build-aux/templates/mbim-error-types.c.template: -------------------------------------------------------------------------------- 1 | /*** BEGIN file-header ***/ 2 | /*** END file-header ***/ 3 | 4 | /*** BEGIN file-production ***/ 5 | /* enumerations from "@filename@" */ 6 | /*** END file-production ***/ 7 | 8 | /*** BEGIN value-header ***/ 9 | static const G@Type@Value @enum_name@_values[] = { 10 | /*** END value-header ***/ 11 | /*** BEGIN value-production ***/ 12 | { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, 13 | /*** END value-production ***/ 14 | /*** BEGIN value-tail ***/ 15 | { 0, NULL, NULL } 16 | }; 17 | 18 | /* @enum_name@_quark() implemented in mbim-errors-quarks.c */ 19 | 20 | GType 21 | @enum_name@_get_type (void) 22 | { 23 | static gsize g_define_type_id_initialized = 0; 24 | 25 | if (g_once_init_enter (&g_define_type_id_initialized)) { 26 | GType g_define_type_id = 27 | g_@type@_register_static (g_intern_static_string ("@EnumName@"), 28 | @enum_name@_values); 29 | g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); 30 | } 31 | 32 | return g_define_type_id_initialized; 33 | } 34 | 35 | /* Enum-specific method to get the value as a string. 36 | * We get the nick of the GEnumValue. Note that this will be 37 | * valid even if the GEnumClass is not referenced anywhere. */ 38 | /** 39 | * @enum_name@_get_string: 40 | * @val: a @EnumName@. 41 | * 42 | * Gets the nickname string for the #@EnumName@ specified at @val. 43 | * 44 | * Returns: (transfer none): a string with the nickname, or %NULL if not found. Do not free the returned value. 45 | */ 46 | const gchar * 47 | @enum_name@_get_string (@EnumName@ val) 48 | { 49 | guint i; 50 | 51 | for (i = 0; @enum_name@_values[i].value_nick; i++) { 52 | if ((gint)val == @enum_name@_values[i].value) 53 | return @enum_name@_values[i].value_nick; 54 | } 55 | 56 | return NULL; 57 | } 58 | 59 | /*** END value-tail ***/ 60 | 61 | /*** BEGIN file-tail ***/ 62 | /*** END file-tail ***/ 63 | -------------------------------------------------------------------------------- /build-aux/templates/mbim-error-types.h.template: -------------------------------------------------------------------------------- 1 | /*** BEGIN file-header ***/ 2 | 3 | #include 4 | 5 | G_BEGIN_DECLS 6 | /*** END file-header ***/ 7 | 8 | /*** BEGIN file-production ***/ 9 | 10 | /* enumerations from "@filename@" */ 11 | /*** END file-production ***/ 12 | 13 | /*** BEGIN value-header ***/ 14 | GQuark @enum_name@_quark (void); 15 | GType @enum_name@_get_type (void) G_GNUC_CONST; 16 | #define @ENUMNAME@ (@enum_name@_quark ()) 17 | #define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) 18 | const gchar *@enum_name@_get_string (@EnumName@ val); 19 | /*** END value-header ***/ 20 | 21 | /*** BEGIN file-tail ***/ 22 | G_END_DECLS 23 | 24 | /*** END file-tail ***/ 25 | -------------------------------------------------------------------------------- /build-aux/templates/mbim-flag-types.c.template: -------------------------------------------------------------------------------- 1 | /*** BEGIN file-header ***/ 2 | 3 | /*** END file-header ***/ 4 | 5 | /*** BEGIN file-production ***/ 6 | /* enumerations from "@filename@" */ 7 | /*** END file-production ***/ 8 | 9 | /*** BEGIN value-header ***/ 10 | static const G@Type@Value @enum_name@_values[] = { 11 | /*** END value-header ***/ 12 | /*** BEGIN value-production ***/ 13 | { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, 14 | /*** END value-production ***/ 15 | /*** BEGIN value-tail ***/ 16 | { 0, NULL, NULL } 17 | }; 18 | 19 | /* Define type-specific symbols */ 20 | 21 | GType 22 | @enum_name@_get_type (void) 23 | { 24 | static gsize g_define_type_id_initialized = 0; 25 | 26 | if (g_once_init_enter (&g_define_type_id_initialized)) { 27 | GType g_define_type_id = 28 | g_@type@_register_static (g_intern_static_string ("@EnumName@"), 29 | @enum_name@_values); 30 | g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); 31 | } 32 | 33 | return g_define_type_id_initialized; 34 | } 35 | 36 | /* Flags-specific method to build a string with the given mask. 37 | * We get a comma separated list of the nicks of the GFlagsValues. 38 | * Note that this will be valid even if the GFlagsClass is not referenced 39 | * anywhere. */ 40 | gchar * 41 | @enum_name@_build_string_from_mask (@EnumName@ mask) 42 | { 43 | guint i; 44 | gboolean first = TRUE; 45 | GString *str = NULL; 46 | 47 | for (i = 0; @enum_name@_values[i].value_nick; i++) { 48 | /* We also look for exact matches */ 49 | if ((guint)mask == @enum_name@_values[i].value) { 50 | if (str) 51 | g_string_free (str, TRUE); 52 | return g_strdup (@enum_name@_values[i].value_nick); 53 | } 54 | 55 | /* Build list with single-bit masks */ 56 | if (mask & @enum_name@_values[i].value) { 57 | guint c; 58 | gulong number = @enum_name@_values[i].value; 59 | 60 | for (c = 0; number; c++) 61 | number &= number - 1; 62 | 63 | if (c == 1) { 64 | if (!str) 65 | str = g_string_new (""); 66 | g_string_append_printf (str, "%s%s", 67 | first ? "" : ", ", 68 | @enum_name@_values[i].value_nick); 69 | if (first) 70 | first = FALSE; 71 | } 72 | } 73 | } 74 | 75 | return (str ? g_string_free (str, FALSE) : NULL); 76 | } 77 | 78 | /*** END value-tail ***/ 79 | 80 | /*** BEGIN file-tail ***/ 81 | /*** END file-tail ***/ 82 | -------------------------------------------------------------------------------- /build-aux/templates/mbim-flag-types.h.template: -------------------------------------------------------------------------------- 1 | /*** BEGIN file-header ***/ 2 | 3 | #include 4 | 5 | G_BEGIN_DECLS 6 | /*** END file-header ***/ 7 | 8 | /*** BEGIN file-production ***/ 9 | 10 | /* enumerations from "@filename@" */ 11 | /*** END file-production ***/ 12 | 13 | /*** BEGIN value-header ***/ 14 | GType @enum_name@_get_type (void) G_GNUC_CONST; 15 | #define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) 16 | 17 | /* Define type-specific symbols */ 18 | #define __@ENUMNAME@_IS_@TYPE@__ 19 | 20 | /** 21 | * @enum_name@_build_string_from_mask: 22 | * @mask: bitmask of @EnumName@ values. 23 | * 24 | * Builds a string containing a comma-separated list of nicknames for 25 | * each #@EnumName@ in @mask. 26 | * 27 | * Returns: (transfer full): a string with the list of nicknames, or %NULL if none given. The returned value should be freed with g_free(). 28 | * 29 | * Since: @enumsince@ 30 | */ 31 | gchar *@enum_name@_build_string_from_mask (@EnumName@ mask); 32 | 33 | /*** END value-header ***/ 34 | 35 | /*** BEGIN file-tail ***/ 36 | G_END_DECLS 37 | 38 | /*** END file-tail ***/ 39 | -------------------------------------------------------------------------------- /data/mbim-service-atds.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "ATDS" }, 5 | 6 | // ********************************************************************************* 7 | { "name" : "Signal", 8 | "type" : "Command", 9 | "since" : "1.16", 10 | "query" : [], 11 | "response" : [ 12 | // 0-31: dBm = -113 + (2*rssi) 13 | // 99: unknown/undetectable 14 | { "name" : "Rssi", 15 | "format" : "guint32" }, 16 | 17 | // 0: BER < 0.2% 18 | // 1: 0.2% < BER < 0.4% 19 | // 2: 0.4% < BER < 0.8% 20 | // 3: 0.8% < BER < 1.6% 21 | // 4: 1.6% < BER < 3.2% 22 | // 5: 3.2% < BER < 6.4% 23 | // 6: 6.4% < BER < 12.8% 24 | // 7: 12.8% < BER 25 | // 99: unknown/undetectable 26 | { "name" : "ErrorRate", 27 | "format" : "guint32" }, 28 | 29 | // 0: -120 or less dBm 30 | // <96: dBm = -120+rscp 31 | // 96: -24 or greater dBm 32 | // 255: unknown/undetectable 33 | { "name" : "Rscp", 34 | "format" : "guint32" }, 35 | 36 | // 0: -24 or less dBm 37 | // <49: dBm = -24 + ((float)ecno/2) 38 | // 49: 0.5 or greater dBm 39 | // 255: unknown/undetectable 40 | { "name" : "Ecno", 41 | "format" : "guint32" }, 42 | 43 | // 0: -19.5 or less dBm 44 | // <34: dBm = -19.5 + ((float)rsrq/2) 45 | // 34: -2.5 or greater dBm 46 | // 255: unknown/undetectable 47 | { "name" : "Rsrq", 48 | "format" : "guint32" }, 49 | 50 | // 0: -140 or less dBm 51 | // <97: dBm = -140 + rsrp 52 | // 97: -43 or greater dBm 53 | // 255: unknown/undetectable 54 | { "name" : "Rsrp", 55 | "format" : "guint32" }, 56 | 57 | // 0: -5 or less dB 58 | // <35: dB = -5 + rssnr 59 | // 35: 30 or greater dB 60 | // 255: unknown/undetectable 61 | { "name" : "Rssnr", 62 | "format" : "guint32" } ] }, 63 | 64 | // ********************************************************************************* 65 | { "name" : "Location", 66 | "type" : "Command", 67 | "since" : "1.16", 68 | "query" : [], 69 | "response" : [ { "name" : "Lac", 70 | "format" : "guint32" }, 71 | { "name" : "Tac", 72 | "format" : "guint32" }, 73 | { "name" : "CellId", 74 | "format" : "guint32" } ] }, 75 | 76 | // ********************************************************************************* 77 | { "name" : "MbimAtdsProvider", 78 | "type" : "Struct", 79 | "since" : "1.16", 80 | "contents" : [ { "name" : "ProviderId", 81 | "format" : "string" }, 82 | { "name" : "ProviderState", 83 | "format" : "guint32", 84 | "public-format" : "MbimProviderState" }, 85 | { "name" : "ProviderName", 86 | "format" : "string" }, 87 | { "name" : "PlmnMode", 88 | "format" : "guint32", 89 | "public-format" : "MbimAtdsProviderPlmnMode" }, 90 | { "name" : "Rssi", 91 | "format" : "guint32" }, 92 | { "name" : "ErrorRate", 93 | "format" : "guint32" } ] }, 94 | 95 | { "name" : "Operators", 96 | "type" : "Command", 97 | "since" : "1.16", 98 | "query" : [], 99 | "response" : [ { "name" : "ProvidersCount", 100 | "format" : "guint32" }, 101 | { "name" : "Providers", 102 | "format" : "ref-struct-array" , 103 | "struct-type" : "MbimAtdsProvider", 104 | "array-size-field" : "ProvidersCount" } ] }, 105 | 106 | // ********************************************************************************* 107 | { "name" : "RAT", 108 | "type" : "Command", 109 | "since" : "1.16", 110 | "set" : [ { "name" : "Mode", 111 | "format" : "guint32", 112 | "public-format" : "MbimAtdsRatMode" } ], 113 | "query" : [], 114 | "response" : [ { "name" : "Mode", 115 | "format" : "guint32", 116 | "public-format" : "MbimAtdsRatMode" } ] }, 117 | 118 | // ********************************************************************************* 119 | { "name" : "Register State", 120 | "type" : "Command", 121 | "since" : "1.16", 122 | "query" : [], 123 | "response" : [ { "name" : "NwError", 124 | "format" : "guint32", 125 | "public-format" : "MbimNwError" }, 126 | { "name" : "RegisterState", 127 | "format" : "guint32", 128 | "public-format" : "MbimRegisterState" }, 129 | { "name" : "RegisterMode", 130 | "format" : "guint32", 131 | "public-format" : "MbimRegisterMode" }, 132 | { "name" : "AvailableDataClasses", 133 | "format" : "guint32", 134 | "public-format" : "MbimDataClass" }, 135 | { "name" : "CurrentCellularClass", 136 | "format" : "guint32", 137 | "public-format" : "MbimCellularClass" }, 138 | { "name" : "ProviderId", 139 | "format" : "string" }, 140 | { "name" : "ProviderName", 141 | "format" : "string" }, 142 | { "name" : "RoamingText", 143 | "format" : "string" }, 144 | { "name" : "RegistrationFlag", 145 | "format" : "guint32", 146 | "public-format" : "MbimRegistrationFlag" } ] } 147 | 148 | ] 149 | -------------------------------------------------------------------------------- /data/mbim-service-auth.json: -------------------------------------------------------------------------------- 1 | 2 | [ 3 | // ********************************************************************************* 4 | { "type" : "Service", 5 | "name" : "Auth" }, 6 | 7 | // ********************************************************************************* 8 | { "name" : "Aka", 9 | "type" : "Command", 10 | "since" : "1.4", 11 | "query" : [ { "name" : "Rand", 12 | "format" : "byte-array", 13 | "array-size" : "16" }, 14 | { "name" : "Autn", 15 | "format" : "byte-array", 16 | "array-size" : "16" } ], 17 | "response" : [ { "name" : "Res", 18 | "format" : "byte-array", 19 | "array-size" : "16" }, 20 | { "name" : "ResLen", 21 | "format" : "guint32" }, 22 | { "name" : "IntegratingKey", 23 | "format" : "byte-array", 24 | "array-size" : "16" }, 25 | { "name" : "CipheringKey", 26 | "format" : "byte-array", 27 | "array-size" : "16" }, 28 | { "name" : "Auts", 29 | "format" : "byte-array", 30 | "array-size" : "14" } ] }, 31 | 32 | // ********************************************************************************* 33 | { "name" : "Akap", 34 | "type" : "Command", 35 | "since" : "1.4", 36 | "query" : [ { "name" : "Rand", 37 | "format" : "byte-array", 38 | "array-size" : "16" }, 39 | { "name" : "Autn", 40 | "format" : "byte-array", 41 | "array-size" : "16" }, 42 | { "name" : "NetworkName", 43 | "format" : "string" } ], 44 | "response" : [ { "name" : "Res", 45 | "format" : "byte-array", 46 | "array-size" : "16" }, 47 | { "name" : "ResLen", 48 | "format" : "guint32" }, 49 | { "name" : "IntegratingKey", 50 | "format" : "byte-array", 51 | "array-size" : "16" }, 52 | { "name" : "CipheringKey", 53 | "format" : "byte-array", 54 | "array-size" : "16" }, 55 | { "name" : "Auts", 56 | "format" : "byte-array", 57 | "array-size" : "14" } ] }, 58 | 59 | // ********************************************************************************* 60 | { "name" : "Sim", 61 | "type" : "Command", 62 | "since" : "1.4", 63 | "query" : [ { "name" : "Rand1", 64 | "format" : "byte-array", 65 | "array-size" : "16" }, 66 | { "name" : "Rand2", 67 | "format" : "byte-array", 68 | "array-size" : "16" }, 69 | { "name" : "Rand3", 70 | "format" : "byte-array", 71 | "array-size" : "16" }, 72 | { "name" : "N", 73 | "format" : "guint32" } ], 74 | "response" : [ { "name" : "Sres1", 75 | "format" : "guint32" }, 76 | { "name" : "Kc1", 77 | "format" : "guint64" }, 78 | { "name" : "Sres2", 79 | "format" : "guint32" }, 80 | { "name" : "Kc2", 81 | "format" : "guint64" }, 82 | { "name" : "Sres3", 83 | "format" : "guint32" }, 84 | { "name" : "Kc3", 85 | "format" : "guint64" }, 86 | { "name" : "N", 87 | "format" : "guint32" } ] } 88 | 89 | ] 90 | -------------------------------------------------------------------------------- /data/mbim-service-compal.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "Compal" }, 5 | 6 | // ********************************************************************************* 7 | { "name" : "AT Command", 8 | "service" : "Compal", 9 | "type" : "Command", 10 | "since" : "1.32", 11 | "query" : [ { "name" : "CommandReq", 12 | "format" : "unsized-byte-array", 13 | "pad-array" : "FALSE", 14 | "personal-info" : "true" } ], 15 | "response" : [ { "name" : "CommandResp", 16 | "format" : "unsized-byte-array", 17 | "personal-info" : "true" } ] } 18 | ] 19 | -------------------------------------------------------------------------------- /data/mbim-service-dss.json: -------------------------------------------------------------------------------- 1 | 2 | [ 3 | // ********************************************************************************* 4 | { "type" : "Service", 5 | "name" : "DSS" }, 6 | 7 | // ********************************************************************************* 8 | { "name" : "Connect", 9 | "type" : "Command", 10 | "since" : "1.4", 11 | "set" : [ { "name" : "DeviceServiceId", 12 | "format" : "uuid" }, 13 | { "name" : "DssSessionId", 14 | "format" : "guint32" }, 15 | { "name" : "DssLinkState", 16 | "format" : "guint32", 17 | "public-format" : "MbimDssLinkState" } ], 18 | "response" : [] } 19 | 20 | ] 21 | -------------------------------------------------------------------------------- /data/mbim-service-fibocom.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "Fibocom" }, 5 | 6 | // ********************************************************************************* 7 | 8 | { "name" : "AT Command", 9 | "type" : "Command", 10 | "since" : "1.32", 11 | "set" : [ { "name" : "CommandReq", 12 | "format" : "unsized-byte-array", 13 | "pad-array" : "FALSE", 14 | "personal-info" : "true" } ], 15 | "response" : [ { "name" : "CommandResp", 16 | "format" : "unsized-byte-array", 17 | "pad-array" : "FALSE", 18 | "personal-info" : "true" } ] } 19 | ] 20 | -------------------------------------------------------------------------------- /data/mbim-service-google.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "Google" }, 5 | 6 | // ********************************************************************************* 7 | { "name" : "Carrier Lock", 8 | "type" : "Command", 9 | "since" : "1.30", 10 | "set" : [ { "name" : "Data", 11 | "format" : "ref-byte-array-no-offset" } ], 12 | "query" : [], 13 | "response" : [ { "name" : "CarrierLockStatus", 14 | "format" : "guint32", 15 | "public-format" : "MbimCarrierLockStatus" }, 16 | { "name" : "CarrierLockModemState", 17 | "format" : "guint32", 18 | "public-format" : "MbimCarrierLockModemState" }, 19 | { "name" : "CarrierLockCause", 20 | "format" : "guint32", 21 | "public-format" : "MbimCarrierLockCause" } ], 22 | "notification" : [ { "name" : "CarrierLockStatus", 23 | "format" : "guint32", 24 | "public-format" : "MbimCarrierLockStatus" }, 25 | { "name" : "CarrierLockModemState", 26 | "format" : "guint32", 27 | "public-format" : "MbimCarrierLockModemState" }, 28 | { "name" : "CarrierLockCause", 29 | "format" : "guint32", 30 | "public-format" : "MbimCarrierLockCause" } ] } 31 | ] 32 | -------------------------------------------------------------------------------- /data/mbim-service-intel-at-tunnel.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "Intel AT Tunnel" }, 5 | 6 | // ********************************************************************************* 7 | { "name" : "AT Command", 8 | "service" : "Intel AT Tunnel", 9 | "type" : "Command", 10 | "since" : "1.34", 11 | "set" : [ { "name" : "CommandReq", 12 | "format" : "unsized-byte-array", 13 | "pad-array" : "FALSE", 14 | "personal-info" : "true" } ], 15 | "response" : [ { "name" : "CommandResp", 16 | "format" : "unsized-byte-array", 17 | "personal-info" : "true" } ] } 18 | ] 19 | -------------------------------------------------------------------------------- /data/mbim-service-intel-firmware-update-v2.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "Intel Firmware Update V2", 5 | "mbimex-service" : "Intel Firmware Update", 6 | "mbimex-version" : "2.0" }, 7 | 8 | // ********************************************************************************* 9 | { "name" : "Modem Reboot", 10 | "type" : "Command", 11 | "since" : "1.28", 12 | "set" : [ { "name" : "BootMode", 13 | "format" : "guint32", 14 | "public-format" : "MbimIntelBootMode" }, 15 | { "name" : "Timeout", 16 | "format" : "guint32" } ] } 17 | ] 18 | -------------------------------------------------------------------------------- /data/mbim-service-intel-firmware-update.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "Intel Firmware Update" }, 5 | 6 | // ********************************************************************************* 7 | { "name" : "Modem Reboot", 8 | "type" : "Command", 9 | "since" : "1.16", 10 | "set" : [] } 11 | ] 12 | -------------------------------------------------------------------------------- /data/mbim-service-intel-mutual-authentication.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "Intel Mutual Authentication" }, 5 | 6 | // ********************************************************************************* 7 | { "name" : "FCC Lock", 8 | "service" : "Intel Mutual Authentication", 9 | "type" : "Command", 10 | "since" : "1.30", 11 | "query" : [], 12 | "set" : [ { "name" : "ResponsePresent", 13 | "format" : "guint32", 14 | "public-format" : "gboolean" }, 15 | { "name" : "Response", 16 | "format" : "guint32" } ], 17 | 18 | "response" : [ { "name" : "ChallengePresent", 19 | "format" : "guint32", 20 | "public-format" : "gboolean" }, 21 | { "name" : "Challenge", 22 | "format" : "guint32" } ] } 23 | ] 24 | -------------------------------------------------------------------------------- /data/mbim-service-intel-thermal-rf.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "Intel Thermal RF" }, 5 | 6 | // *********************************************************************************** 7 | 8 | { "name" : "MbimIntelRfimFrequencyValue", 9 | "type" : "Struct", 10 | "since" : "1.28", 11 | "contents" : [ { "name" : "ServingCellInfo", 12 | "format" : "guint32", 13 | "public-format" : "MbimIntelServingCellInfo" }, 14 | { "name" : "CenterFrequency", 15 | "format" : "guint64" }, 16 | { "name" : "Bandwidth", 17 | "format" : "guint32" }, 18 | 19 | // 0: -140 or less dBm 20 | // <97: dBm = -140 + rsrp 21 | // 97: -43 or greater dBm 22 | // 0xFFFFFFFF: unknown/undetectable 23 | { "name" : "RSRP", 24 | "format" : "guint32" }, 25 | 26 | // 0: -19.5 or less dB 27 | // <34: dB = -19.5 + ((float)rsrq/2) 28 | // 34: -2.5 or greater dB 29 | // 0xFFFFFFFF: unknown/undetectable 30 | { "name" : "RSRQ", 31 | "format" : "guint32" }, 32 | 33 | // 0: -23 or less dB 34 | //<127: ((float)sinr/2) - 23 35 | // 127: 40 or greater dB 36 | // 0xFFFFFFFF: unknown/undetectable 37 | { "name" : "SINR", 38 | "format" : "guint32" }, 39 | 40 | // 0-31: dBm = -113 + (2*rssi) 41 | // 99: unknown/undetectable 42 | { "name" : "RSSI", 43 | "format" : "guint32" }, 44 | { "name" : "ConnectionStatus", 45 | "format" : "guint32", 46 | "public-format" : "gboolean" } ] }, 47 | 48 | { "name" : "RFIM", 49 | "type" : "Command", 50 | "service" : "Intel Thermal RF", 51 | "since" : "1.28", 52 | "set" : [ { "name" : "ActivationState", 53 | "format" : "guint32", 54 | "public-format" : "gboolean" } ], 55 | 56 | "query" : [], 57 | 58 | "response" : [ { "name" : "RfimFrequencyValuesCount", 59 | "format" : "guint32" }, 60 | { "name" : "RfimFrequencyValues", 61 | "format" : "ref-struct-array", 62 | "struct-type" : "MbimIntelRfimFrequencyValue", 63 | "array-size-field" : "RfimFrequencyValuesCount" } ], 64 | 65 | "notification" : [ { "name" : "RfimFrequencyValuesCount", 66 | "format" : "guint32" }, 67 | { "name" : "RfimFrequencyValues", 68 | "format" : "ref-struct-array", 69 | "struct-type" : "MbimIntelRfimFrequencyValue", 70 | "array-size-field" : "RfimFrequencyValuesCount" } ] } 71 | ] 72 | -------------------------------------------------------------------------------- /data/mbim-service-intel-tools.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "Intel Tools" }, 5 | 6 | // ********************************************************************************* 7 | 8 | { "name" : "Trace Config", 9 | "type" : "Command", 10 | "since" : "1.30", 11 | "set" : [ { "name" : "TraceCmd", 12 | "format" : "guint32", 13 | "public-format" : "MbimTraceCommand" }, 14 | { "name" : "TraceValue", 15 | "format" : "guint32" } ], 16 | "query" : [ { "name" : "TraceCmd", 17 | "format" : "guint32", 18 | "public-format" : "MbimTraceCommand" } ], 19 | "response" : [ { "name" : "TraceCmd", 20 | "format" : "guint32", 21 | "public-format" : "MbimTraceCommand" }, 22 | { "name" : "Result", 23 | "format" : "guint32" } ] } 24 | ] 25 | -------------------------------------------------------------------------------- /data/mbim-service-ms-basic-connect-extensions-v2.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "Ms Basic Connect Extensions V2", 5 | "mbimex-service" : "Ms Basic Connect Extensions", 6 | "mbimex-version" : "2.0" }, 7 | 8 | // ********************************************************************************* 9 | 10 | { "name" : "Version", 11 | "type" : "Command", 12 | "since" : "1.28", 13 | "query" : [ { "name" : "MbimVersion", 14 | "format" : "guint16" }, 15 | { "name" : "MbimExtendedVersion", 16 | "format" : "guint16" } ], 17 | "response" : [ { "name" : "MbimVersion", 18 | "format" : "guint16" }, 19 | { "name" : "MbimExtendedVersion", 20 | "format" : "guint16" } ] } 21 | ] 22 | -------------------------------------------------------------------------------- /data/mbim-service-ms-firmware-id.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "MS Firmware ID" }, 5 | 6 | // ********************************************************************************* 7 | { "name" : "Get", 8 | "type" : "Command", 9 | "since" : "1.8", 10 | "query" : [], 11 | "response" : [ { "name" : "FirmwareId", 12 | "format" : "uuid" } ] } 13 | ] 14 | -------------------------------------------------------------------------------- /data/mbim-service-ms-host-shutdown.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "MS Host Shutdown" }, 5 | 6 | // ********************************************************************************* 7 | { "name" : "Notify", 8 | "type" : "Command", 9 | "since" : "1.8", 10 | "set" : [] } 11 | ] 12 | -------------------------------------------------------------------------------- /data/mbim-service-ms-sar.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "MS SAR" }, 5 | 6 | // ********************************************************************************* 7 | 8 | { "name" : "MbimSarConfigState", 9 | "type" : "Struct", 10 | "since" : "1.26", 11 | "contents" : [ { "name" : "AntennaIndex", 12 | "format" : "guint32" }, 13 | { "name" : "BackoffIndex", 14 | "format" : "guint32" } ] }, 15 | 16 | { "name" : "Config", 17 | "type" : "Command", 18 | "since" : "1.26", 19 | "set" : [ { "name" : "Mode", 20 | "format" : "guint32", 21 | "public-format" : "MbimSarControlMode" }, 22 | { "name" : "BackoffState", 23 | "format" : "guint32", 24 | "public-format" : "MbimSarBackoffState" }, 25 | { "name" : "ConfigStatesCount", 26 | "format" : "guint32" }, 27 | { "name" : "ConfigStates", 28 | "format" : "ref-struct-array" , 29 | "struct-type" : "MbimSarConfigState", 30 | "array-size-field" : "ConfigStatesCount" } ], 31 | "query" : [], 32 | "response" : [ { "name" : "Mode", 33 | "format" : "guint32", 34 | "public-format" : "MbimSarControlMode" }, 35 | { "name" : "BackoffState", 36 | "format" : "guint32", 37 | "public-format" : "MbimSarBackoffState" }, 38 | { "name" : "WifiIntegration", 39 | "format" : "guint32", 40 | "public-format" : "MbimSarWifiHardwareState" }, 41 | { "name" : "ConfigStatesCount", 42 | "format" : "guint32" }, 43 | { "name" : "ConfigStates", 44 | "format" : "ref-struct-array" , 45 | "struct-type" : "MbimSarConfigState", 46 | "array-size-field" : "ConfigStatesCount" } ] }, 47 | 48 | // ********************************************************************************* 49 | 50 | { "name" : "Transmission status", 51 | "type" : "Command", 52 | "since" : "1.26", 53 | "set" : [ { "name" : "ChannelNotification", 54 | "format" : "guint32" , 55 | "public-format" : "MbimTransmissionNotificationStatus"}, 56 | { "name" : "HysteresisTimer", 57 | "format" : "guint32" } ], 58 | "query" : [], 59 | "response" : [ { "name" : "ChannelNotification", 60 | "format" : "guint32" , 61 | "public-format" : "MbimTransmissionNotificationStatus"}, 62 | { "name" : "TransmissionStatus", 63 | "format" : "guint32" , 64 | "public-format" : "MbimTransmissionState"}, 65 | { "name" : "HysteresisTimer", 66 | "format" : "guint32" } ], 67 | "notification" : [ { "name" : "ChannelNotification", 68 | "format" : "guint32" , 69 | "public-format" : "MbimTransmissionNotificationStatus"}, 70 | { "name" : "TransmissionStatus", 71 | "format" : "guint32" , 72 | "public-format" : "MbimTransmissionState"}, 73 | { "name" : "HysteresisTimer", 74 | "format" : "guint32" } ] } 75 | ] 76 | -------------------------------------------------------------------------------- /data/mbim-service-ms-voice-extensions.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ************************************************************************ 3 | { "type" : "Service", 4 | "name" : "MS Voice Extensions" }, 5 | 6 | // ************************************************************************ 7 | { "name" : "NITZ", 8 | "type" : "Command", 9 | "since" : "1.28", 10 | "query" : [ ], 11 | "response" : [ { "name" : "Year", 12 | "format" : "guint32" }, 13 | { "name" : "Month", 14 | "format" : "guint32" }, 15 | { "name" : "Day", 16 | "format" : "guint32" }, 17 | { "name" : "Hour", 18 | "format" : "guint32" }, 19 | { "name" : "Minute", 20 | "format" : "guint32" }, 21 | { "name" : "Second", 22 | "format" : "guint32" }, 23 | { "name" : "TimeZoneOffsetMinutes", 24 | "format" : "guint32" }, 25 | { "name" : "DaylightSavingTimeOffsetMinutes", 26 | "format" : "guint32" }, 27 | { "name" : "DataClass", 28 | "format" : "guint32", 29 | "public-format" : "MbimDataClass" } ], 30 | "notification" : [ { "name" : "Year", 31 | "format" : "guint32" }, 32 | { "name" : "Month", 33 | "format" : "guint32" }, 34 | { "name" : "Day", 35 | "format" : "guint32" }, 36 | { "name" : "Hour", 37 | "format" : "guint32" }, 38 | { "name" : "Minute", 39 | "format" : "guint32" }, 40 | { "name" : "Second", 41 | "format" : "guint32" }, 42 | { "name" : "TimeZoneOffsetMinutes", 43 | "format" : "guint32" }, 44 | { "name" : "DaylightSavingTimeOffsetMinutes", 45 | "format" : "guint32" }, 46 | { "name" : "DataClass", 47 | "format" : "guint32", 48 | "public-format" : "MbimDataClass" } ] } 49 | ] 50 | -------------------------------------------------------------------------------- /data/mbim-service-phonebook.json: -------------------------------------------------------------------------------- 1 | 2 | [ 3 | // ********************************************************************************* 4 | { "type" : "Service", 5 | "name" : "Phonebook" }, 6 | 7 | // ********************************************************************************* 8 | { "name" : "Configuration", 9 | "type" : "Command", 10 | "since" : "1.4", 11 | "query" : [], 12 | "response" : [ { "name" : "State", 13 | "format" : "guint32", 14 | "public-format" : "MbimPhonebookState" }, 15 | { "name" : "NumberOfEntries", 16 | "format" : "guint32" }, 17 | { "name" : "UsedEntries", 18 | "format" : "guint32" }, 19 | { "name" : "MaxNumberLength", 20 | "format" : "guint32" }, 21 | { "name" : "MaxName", 22 | "format" : "guint32" } ], 23 | "notification" : [ { "name" : "State", 24 | "format" : "guint32", 25 | "public-format" : "MbimPhonebookState" }, 26 | { "name" : "NumberOfEntries", 27 | "format" : "guint32" }, 28 | { "name" : "UsedEntries", 29 | "format" : "guint32" }, 30 | { "name" : "MaxNumberLength", 31 | "format" : "guint32" }, 32 | { "name" : "MaxName", 33 | "format" : "guint32" } ] }, 34 | 35 | // ********************************************************************************* 36 | { "name" : "MbimPhonebookEntry", 37 | "type" : "Struct", 38 | "since" : "1.4", 39 | "contents" : [ { "name" : "EntryIndex", 40 | "format" : "guint32" }, 41 | { "name" : "Number", 42 | "format" : "string", 43 | "personal-info" : "true" }, 44 | { "name" : "Name", 45 | "format" : "string", 46 | "personal-info" : "true" } ] }, 47 | 48 | { "name" : "Read", 49 | "type" : "Command", 50 | "since" : "1.4", 51 | "query" : [ { "name" : "FilterFlag", 52 | "format" : "guint32", 53 | "public-format" : "MbimPhonebookFlag" }, 54 | { "name" : "FilterMessageIndex", 55 | "format" : "guint32" } ], 56 | "response" : [ { "name" : "EntryCount", 57 | "format" : "guint32" }, 58 | { "name" : "Entries", 59 | "format" : "ref-struct-array", 60 | "struct-type" : "MbimPhonebookEntry", 61 | "array-size-field" : "EntryCount" } ] }, 62 | 63 | // ********************************************************************************* 64 | { "name" : "Delete", 65 | "type" : "Command", 66 | "since" : "1.4", 67 | "set" : [ { "name" : "FilterFlag", 68 | "format" : "guint32", 69 | "public-format" : "MbimPhonebookFlag" }, 70 | { "name" : "FilterMessageIndex", 71 | "format" : "guint32" } ], 72 | "response" : [] }, 73 | 74 | 75 | // ********************************************************************************* 76 | { "name" : "Write", 77 | "type" : "Command", 78 | "since" : "1.4", 79 | "set" : [ { "name" : "SaveFlag", 80 | "format" : "guint32", 81 | "public-format" : "MbimPhonebookWriteFlag" }, 82 | { "name" : "SaveIndex", 83 | "format" : "guint32" }, 84 | { "name" : "Number", 85 | "format" : "string", 86 | "personal-info" : "true" }, 87 | { "name" : "Name", 88 | "format" : "string", 89 | "personal-info" : "true" } ], 90 | "response" : [] } 91 | 92 | ] 93 | -------------------------------------------------------------------------------- /data/mbim-service-proxy-control.json: -------------------------------------------------------------------------------- 1 | 2 | [ 3 | // ********************************************************************************* 4 | { "type" : "Service", 5 | "name" : "Proxy Control" }, 6 | 7 | // ********************************************************************************* 8 | { "name" : "Configuration", 9 | "type" : "Command", 10 | "since" : "1.10", 11 | "set" : [ { "name" : "DevicePath", 12 | "format" : "string" }, 13 | { "name" : "Timeout", 14 | "format" : "guint32" } ], 15 | "response" : [] }, 16 | 17 | // ********************************************************************************* 18 | { "name" : "Version", 19 | "type" : "Command", 20 | "since" : "1.28", 21 | "notification" : [ { "name" : "MbimVersion", 22 | "format" : "guint16" }, 23 | { "name" : "MbimExtendedVersion", 24 | "format" : "guint16" } ] } 25 | ] 26 | -------------------------------------------------------------------------------- /data/mbim-service-qdu.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "QDU" }, 5 | 6 | // ********************************************************************************* 7 | { "name" : "Update Session", 8 | "type" : "Command", 9 | "since" : "1.26", 10 | "set" : [ { "name" : "SessionAction", 11 | "format" : "guint32", 12 | "public-format" : "MbimQduSessionAction" }, 13 | { "name" : "SessionType", 14 | "format" : "guint32", 15 | "public-format" : "MbimQduSessionType" } ], 16 | "query" : [], 17 | "response" : [ { "name" : "CurrentSessionType", 18 | "format" : "guint32", 19 | "public-format" : "MbimQduSessionType" }, 20 | { "name" : "CurrentSessionStatus", 21 | "format" : "guint32", 22 | "public-format" : "MbimQduSessionStatus" }, 23 | { "name" : "LastSessionType", 24 | "format" : "guint32", 25 | "public-format" : "MbimQduSessionType" }, 26 | { "name" : "LastSessionResult", 27 | "format" : "guint32", 28 | "public-format" : "MbimQduSessionResult" }, 29 | { "name" : "LastSessionErrorOffset", 30 | "format" : "guint32" }, 31 | { "name" : "LastSessionErrorSize", 32 | "format" : "guint32" } ] }, 33 | 34 | // ********************************************************************************* 35 | { "name" : "File Open", 36 | "type" : "Command", 37 | "since" : "1.26", 38 | "set" : [ { "name" : "FileType", 39 | "format" : "guint32", 40 | "public-format" : "MbimQduFileType" }, 41 | { "name" : "FileSize", 42 | "format" : "guint32" } ], 43 | "query" : [], 44 | "response" : [ { "name" : "MaxTransferSize", 45 | "format" : "guint32" }, 46 | { "name" : "MaxWindowSize", 47 | "format" : "guint32" } ] }, 48 | 49 | // ********************************************************************************* 50 | { "name" : "File Write", 51 | "type" : "Command", 52 | "since" : "1.26", 53 | "set" : [ { "name" : "DataBuffer", 54 | "format" : "unsized-byte-array", 55 | "pad-array" : "FALSE" } ], 56 | "response" : []}, 57 | 58 | // ********************************************************************************* 59 | { "name" : "Quectel Reboot", 60 | "type" : "Command", 61 | "since" : "1.28", 62 | "set" : [ { "name" : "RebootType", 63 | "format" : "guint16", 64 | "public-format" : "MbimQduQuectelRebootType" } ], 65 | "response" : []}, 66 | 67 | // ********************************************************************************* 68 | { "name" : "Quectel Read Version", 69 | "type" : "Command", 70 | "since" : "1.28", 71 | "set" : [ { "name" : "VersionType", 72 | "format" : "guint16", 73 | "public-format" : "MbimQduQuectelVersionType" } ], 74 | "response" : [ { "name" : "VersionId", 75 | "format" : "guint32" }, 76 | { "name" : "Version", 77 | "format" : "string", 78 | "max-size" : "120" } ] }, 79 | 80 | // ********************************************************************************* 81 | { "name" : "Command", 82 | "type" : "Command", 83 | "since" : "1.32", 84 | "set" : [ { "name" : "CommandType", 85 | "format" : "guint32", 86 | "public-format" : "MbimQuectelCommandType"}, 87 | { "name" : "CommandString", 88 | "format" : "unsized-byte-array", 89 | "pad-array" : "FALSE", 90 | "personal-info" : "true"} ], 91 | "response" : [ { "name" : "CommandResponseStatus", 92 | "format" : "guint32", 93 | "public-format" : "MbimQuectelCommandResponseStatus"}, 94 | { "name" : "CommandResponseString", 95 | "format" : "unsized-byte-array", 96 | "personal-info" : "true"} ] } 97 | ] 98 | -------------------------------------------------------------------------------- /data/mbim-service-qmi.json: -------------------------------------------------------------------------------- 1 | 2 | [ 3 | // ********************************************************************************* 4 | { "type" : "Service", 5 | "name" : "QMI" }, 6 | 7 | // ********************************************************************************* 8 | { "name" : "msg", 9 | "type" : "Command", 10 | "since-ex" : { "set" : "1.14", 11 | "response" : "1.14", 12 | "notification" : "1.18" }, 13 | "set" : [ { "name" : "QmiMsg", 14 | "format" : "unsized-byte-array", 15 | "pad-array" : "FALSE", 16 | "personal-info" : "true" } ], 17 | "response" : [ { "name" : "QMUX", 18 | "format" : "unsized-byte-array", 19 | "pad-array" : "FALSE", 20 | "personal-info" : "true"} ], 21 | "notification" : [ { "name" : "QMUX", 22 | "format" : "unsized-byte-array", 23 | "pad-array" : "FALSE", 24 | "personal-info" : "true"} ]} 25 | ] 26 | -------------------------------------------------------------------------------- /data/mbim-service-quectel.json: -------------------------------------------------------------------------------- 1 | [ 2 | // ********************************************************************************* 3 | { "type" : "Service", 4 | "name" : "Quectel" }, 5 | 6 | // ********************************************************************************* 7 | 8 | { "name" : "Radio State", 9 | "type" : "Command", 10 | "since" : "1.26.2", 11 | "set" : [ { "name" : "RadioState", 12 | "format" : "guint32", 13 | "public-format" : "MbimQuectelRadioSwitchState" } ], 14 | "query" : [], 15 | "response" : [ { "name" : "RadioState", 16 | "format" : "guint32", 17 | "public-format" : "MbimQuectelRadioSwitchState" } ] } 18 | ] 19 | -------------------------------------------------------------------------------- /data/mbim-service-stk.json: -------------------------------------------------------------------------------- 1 | 2 | [ 3 | // ********************************************************************************* 4 | { "type" : "Service", 5 | "name" : "STK" }, 6 | 7 | // ********************************************************************************* 8 | { "name" : "Pac", 9 | "type" : "Command", 10 | "since" : "1.4", 11 | "query" : [], 12 | "set" : [ { "name" : "PacHostControl", 13 | "format" : "byte-array", 14 | "array-size" : "32" } ], 15 | "response" : [ { "name" : "PacSupport", 16 | "format" : "byte-array", 17 | "array-size" : "256" } ], 18 | "notification" : [ { "name" : "PacType", 19 | "format" : "guint32", 20 | "public-format" : "MbimStkPacType" }, 21 | { "name" : "DataBuffer", 22 | "format" : "unsized-byte-array" } ] }, 23 | 24 | // ********************************************************************************* 25 | { "name" : "Terminal Response", 26 | "type" : "Command", 27 | "since" : "1.4", 28 | "set" : [ { "name" : "Response", 29 | "format" : "ref-byte-array-no-offset" } ], 30 | "response" : [ { "name" : "ResultData", 31 | "format" : "ref-byte-array" }, 32 | { "name" : "StatusWords", 33 | "format" : "guint32" } ] }, 34 | 35 | // ********************************************************************************* 36 | { "name" : "Envelope", 37 | "type" : "Command", 38 | "since" : "1.4", 39 | "query" : [], 40 | "set" : [ { "name" : "Data", 41 | "format" : "unsized-byte-array" } ], 42 | // This response is only for the 'query', the 'set' one is empty... 43 | "response" : [ { "name" : "EnvelopeSupport", 44 | "format" : "byte-array", 45 | "array-size" : "32" } ] } 46 | ] 47 | -------------------------------------------------------------------------------- /data/mbim-service-ussd.json: -------------------------------------------------------------------------------- 1 | 2 | [ 3 | // ********************************************************************************* 4 | { "type" : "Service", 5 | "name" : "USSD" }, 6 | 7 | // ********************************************************************************* 8 | { "name" : "", 9 | "type" : "Command", 10 | "since" : "1.4", 11 | "set" : [ { "name" : "Action", 12 | "format" : "guint32", 13 | "public-format" : "MbimUssdAction" }, 14 | { "name" : "DataCodingScheme", 15 | "format" : "guint32" }, 16 | { "name" : "Payload", 17 | "format" : "ref-byte-array" } ], 18 | "response" : [ { "name" : "Response", 19 | "format" : "guint32", 20 | "public-format" : "MbimUssdResponse" }, 21 | { "name" : "SessionState", 22 | "format" : "guint32", 23 | "public-format" : "MbimUssdSessionState" }, 24 | { "name" : "DataCodingScheme", 25 | "format" : "guint32" }, 26 | { "name" : "Payload", 27 | "format" : "ref-byte-array" } ], 28 | "notification" : [ { "name" : "Response", 29 | "format" : "guint32", 30 | "public-format" : "MbimUssdResponse" }, 31 | { "name" : "SessionState", 32 | "format" : "guint32", 33 | "public-format" : "MbimUssdSessionState" }, 34 | { "name" : "DataCodingScheme", 35 | "format" : "guint32" }, 36 | { "name" : "Payload", 37 | "format" : "ref-byte-array" } ] } 38 | ] 39 | -------------------------------------------------------------------------------- /docs/libmbim-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/linux-mobile-broadband/libmbim/e10df4b6b3edfe6a46d93f7f5f5cab31c29a7091/docs/libmbim-logo.png -------------------------------------------------------------------------------- /docs/man/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | help2man = find_program('help2man') 5 | 6 | mans = [ 7 | ['mbimcli', [help2man, '--output=@OUTPUT@', '--name=Control MBIM devices', '--help-option="--help-all"', mbimcli], [mbimcli_sources]], 8 | ['mbim-network', [help2man, '--output=@OUTPUT@', '--name=Simple network management of MBIM devices', mbim_network], []], 9 | ] 10 | 11 | foreach man: mans 12 | custom_target( 13 | man[0], 14 | output: man[0] + '.1', 15 | command: man[1], 16 | depend_files: man[2], 17 | install: true, 18 | install_dir: mbim_mandir / 'man1', 19 | ) 20 | endforeach 21 | -------------------------------------------------------------------------------- /docs/reference/libmbim-glib/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | subdir('xml') 5 | 6 | doc_module = 'libmbim-glib' 7 | 8 | src_dirs = [ 9 | generated_inc, 10 | libmbim_glib_inc, 11 | ] 12 | 13 | private_headers = [ 14 | 'mbim-helpers.h', 15 | 'mbim-helpers-netlink.h', 16 | 'mbim-message-private.h', 17 | 'mbim-net-port-manager.h', 18 | 'mbim-net-port-manager-wdm.h', 19 | 'mbim-net-port-manager-wwan.h', 20 | 'wwan.h', 21 | ] 22 | 23 | scan_args = [ 24 | '--rebuild-types', 25 | '--deprecated-guards="MBIM_DISABLE_DEPRECATED"', 26 | ] 27 | 28 | glib_prefix = glib_dep.get_pkgconfig_variable('prefix') 29 | 30 | fixxref_args = [ 31 | '--html-dir=' + (mbim_prefix / gnome.gtkdoc_html_dir(doc_module)), 32 | '--extra-dir=' + (glib_prefix / gnome.gtkdoc_html_dir('glib')), 33 | '--extra-dir=' + (glib_prefix / gnome.gtkdoc_html_dir('gio')), 34 | ] 35 | 36 | name = doc_module + '-sections.txt' 37 | 38 | ''' 39 | FIXME: gen_sections should be used in the `input` field but it would add 40 | a dependency over file paths that are not yet created, so 41 | the `depends` section is used to generate alternate dependency. 42 | This is fixed in newer meson versions. 43 | ''' 44 | sections_txt = custom_target( 45 | name, 46 | input: 'libmbim-glib-common.sections', 47 | output: name, 48 | capture: true, 49 | command: [find_program('cat'), '@INPUT@'] + gen_sections, 50 | depends: gen_sections_deps, 51 | build_by_default: true, 52 | ) 53 | 54 | version_xml = configure_file( 55 | input: 'version.xml.in', 56 | output: '@BASENAME@', 57 | configuration: version_conf, 58 | ) 59 | 60 | gnome.gtkdoc( 61 | doc_module, 62 | main_xml: doc_module + '-docs.xml', 63 | src_dir: src_dirs, 64 | ignore_headers: private_headers, 65 | include_directories: top_inc, 66 | gobject_typesfile: doc_module + '.types', 67 | dependencies: libmbim_glib_dep, 68 | namespace: 'mbim', 69 | scan_args: scan_args, 70 | fixxref_args: fixxref_args, 71 | content_files: [sections_txt, version_xml], 72 | install: true, 73 | check: true, 74 | ) 75 | -------------------------------------------------------------------------------- /docs/reference/libmbim-glib/version.xml.in: -------------------------------------------------------------------------------- 1 | @VERSION@ 2 | -------------------------------------------------------------------------------- /docs/reference/libmbim-glib/xml/gtkdocentities.ent.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /docs/reference/libmbim-glib/xml/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | ent_conf = { 5 | 'PACKAGE': mbim_name, 6 | 'PACKAGE_BUGREPORT': mbim_name + '-devel@lists.freedesktop.org', 7 | 'PACKAGE_NAME': mbim_name, 8 | 'PACKAGE_STRING': '@0@ @1@'.format(mbim_name, mbim_version), 9 | 'PACKAGE_TARNAME': mbim_name, 10 | 'PACKAGE_URL': '', 11 | 'PACKAGE_VERSION': mbim_version, 12 | } 13 | 14 | gtkdocentities_ent = configure_file( 15 | input: 'gtkdocentities.ent.in', 16 | output: '@BASENAME@', 17 | configuration: ent_conf, 18 | ) 19 | -------------------------------------------------------------------------------- /examples/simple-tester-c/README: -------------------------------------------------------------------------------- 1 | 2 | The simple-tester-c program makes use of the 'libmbim-glib' library. 3 | 4 | The program will: 5 | * Open a connection to the mbim-proxy, or launch the mbim-proxy itself 6 | if it isn't already running. 7 | * Query device capabilities. 8 | 9 | The output will look like this: 10 | 11 | $ ./simple-tester-c /dev/cdc-wdm0 12 | device type: embedded 13 | cellular class: gsm 14 | voice class: no-voice 15 | sim class: removable 16 | data class: gprs, edge, umts, hsdpa, hsupa, lte 17 | sms capabilities: pdu-receive, pdu-send 18 | control capabilities: reg-manual 19 | max sessions: 8 20 | custom data class: None 21 | device id: 013937003110648 22 | firmware info: FIH7160_V1.1_MODEM_01.1349.12 23 | hardware info: XMM7160_V1.1_MBIM_GNSS_NAND_RE 24 | 25 | Have fun! 26 | -------------------------------------------------------------------------------- /examples/simple-tester-c/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2024 Aleksander Morgado 3 | 4 | executable( 5 | 'simple-tester-c', 6 | sources: 'simple-tester-c.c', 7 | include_directories: top_inc, 8 | dependencies: libmbim_glib_dep, 9 | ) 10 | -------------------------------------------------------------------------------- /examples/simple-tester-python/README: -------------------------------------------------------------------------------- 1 | 2 | The simple-tester-python program makes use of the 'libmbim-glib' library 3 | through GObject Introspection. 4 | 5 | The program will: 6 | * Open a connection to the mbim-proxy, or launch the mbim-proxy itself 7 | if it isn't already running. 8 | * Query device capabilities 9 | 10 | The output will look like this: 11 | 12 | $ ./simple-tester-python /dev/cdc-wdm0 13 | device type: embedded 14 | cellular class: gsm 15 | voice class: no-voice 16 | sim class: removable 17 | data class: gprs, edge, umts, hsdpa, hsupa, lte 18 | sms capabilities: pdu-receive, pdu-send 19 | control capabilities: reg-manual 20 | max sessions: 8 21 | custom data class: None 22 | device id: 013937003110648 23 | firmware info: FIH7160_V1.1_MODEM_01.1349.12 24 | hardware info: XMM7160_V1.1_MBIM_GNSS_NAND_RE 25 | 26 | Note that the program requires libmbim-glib to be installed in the system 27 | and the introspection typelibs available in the standard paths. 28 | 29 | Have fun! -------------------------------------------------------------------------------- /examples/simple-tester-python/simple-tester-python: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 3 | # 4 | # This program is free software; you can redistribute it and/or modify it under 5 | # the terms of the GNU Lesser General Public License as published by the Free 6 | # Software Foundation; either version 2 of the License, or (at your option) any 7 | # later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, but WITHOUT 10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 12 | # details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public License along 15 | # with this program; if not, write to the Free Software Foundation, Inc., 51 16 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | # 18 | # Copyright (C) 2020 Aleksander Morgado 19 | # 20 | 21 | import sys, signal, gi 22 | 23 | gi.require_version('Mbim', '1.0') 24 | from gi.repository import GLib, Gio, Mbim 25 | 26 | main_loop = None 27 | 28 | 29 | def signal_handler(data): 30 | main_loop.quit() 31 | 32 | 33 | def close_ready(device,result,user_data=None): 34 | try: 35 | device.close_finish(result) 36 | except GLib.GError as error: 37 | sys.stderr.write("Couldn't close MBIM device: %s\n" % error.message) 38 | main_loop.quit() 39 | 40 | 41 | def query_device_caps_ready(device,result,user_data=None): 42 | try: 43 | response = device.command_finish(result) 44 | response.command_done_get_result() 45 | success, devtype, cellclass, voiceclass, simclass, dataclass, smscaps, controlcaps, maxsessions, customdataclass, deviceid, firmwareinfo, hardwareinfo = response.device_caps_response_parse() 46 | 47 | if success: 48 | print("device type: %s" % Mbim.DeviceType.get_string(devtype)) 49 | print("cellular class: %s" % Mbim.CellularClass.build_string_from_mask(cellclass)) 50 | print("voice class: %s" % Mbim.VoiceClass.get_string(voiceclass)) 51 | print("sim class: %s" % Mbim.SimClass.build_string_from_mask(simclass)) 52 | print("data class: %s" % Mbim.DataClass.build_string_from_mask(dataclass)) 53 | print("sms capabilities: %s" % Mbim.SmsCaps.build_string_from_mask(smscaps)) 54 | print("control capabilities: %s" % Mbim.CtrlCaps.build_string_from_mask(controlcaps)) 55 | print("max sessions: %u" % maxsessions) 56 | print("custom data class: %s" % customdataclass) 57 | print("device id: %s" % deviceid) 58 | print("firmware info: %s" % firmwareinfo) 59 | print("hardware info: %s" % hardwareinfo) 60 | 61 | except GLib.GError as error: 62 | sys.stderr.write("Couldn't run MBIM command: %s\n" % error.message) 63 | 64 | device.close(10, None, close_ready, None) 65 | 66 | 67 | def open_full_ready(device,result,user_data=None): 68 | try: 69 | device.open_full_finish(result) 70 | except GLib.GError as error: 71 | sys.stderr.write("Couldn't open MBIM device: %s\n" % error.message) 72 | main_loop.quit() 73 | return 74 | 75 | request = Mbim.Message.device_caps_query_new () 76 | device.command(request, 10, None, query_device_caps_ready, None) 77 | 78 | 79 | def new_ready(unused,result,user_data=None): 80 | try: 81 | device = Mbim.Device.new_finish(result) 82 | except GLib.GError as error: 83 | sys.stderr.write("Couldn't create MBIM device: %s\n" % error.message) 84 | main_loop.quit() 85 | return 86 | 87 | device.open_full(Mbim.DeviceOpenFlags.PROXY, 10, None, open_full_ready, None) 88 | 89 | 90 | if __name__ == "__main__": 91 | 92 | # Process input arguments 93 | if len(sys.argv) != 2: 94 | sys.stderr.write('error: wrong number of arguments\n') 95 | sys.stdout.write('usage: simple-tester-python \n') 96 | sys.exit(1) 97 | 98 | # Create Mbim device asynchronously 99 | file = Gio.File.new_for_path(sys.argv[1]) 100 | Mbim.Device.new (file, None, new_ready, None) 101 | 102 | # Main loop 103 | main_loop = GLib.MainLoop() 104 | GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGHUP, signal_handler, None) 105 | GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGTERM, signal_handler, None) 106 | try: 107 | main_loop.run() 108 | except KeyboardInterrupt: 109 | pass 110 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | project( 5 | 'libmbim', 'c', 6 | version: '1.33.1', 7 | license: ['GPL-2.0-or-later', 'LGPL-2.1-or-later'], 8 | default_options: [ 9 | 'buildtype=debugoptimized', 10 | 'c_std=gnu89', 11 | 'warning_level=2', 12 | ], 13 | meson_version: '>= 0.53.0', 14 | ) 15 | 16 | mbim_name = meson.project_name() 17 | mbim_version = meson.project_version() 18 | version_array = mbim_version.split('.') 19 | mbim_major_version = version_array[0].to_int() 20 | mbim_minor_version = version_array[1].to_int() 21 | mbim_micro_version = version_array[2].to_int() 22 | 23 | mbim_prefix = get_option('prefix') 24 | mbim_bindir = get_option('bindir') 25 | mbim_datadir = get_option('datadir') 26 | mbim_includedir = get_option('includedir') 27 | mbim_libexecdir = get_option('libexecdir') 28 | mbim_mandir = get_option('mandir') 29 | 30 | mbim_glib_include_subdir = mbim_name + '-glib' 31 | mbim_glib_pkgincludedir = mbim_includedir / mbim_glib_include_subdir 32 | 33 | # libtool versioning for libmbim-glib (-version-info c:r:a) 34 | # - If the interface is unchanged, but the implementation has changed or been fixed, then increment r 35 | # - Otherwise, increment c and zero r. 36 | # - If the interface has grown (that is, the new library is compatible with old code), increment a. 37 | # - If the interface has changed in an incompatible way (that is, functions have changed or been removed), then zero a. 38 | current = 13 39 | revision = 0 40 | age = 9 41 | mbim_glib_version = '@0@.@1@.@2@'.format(current - age, age, revision) 42 | 43 | mbim_gir_version = '1.0' 44 | 45 | gnome = import('gnome') 46 | i18n = import('i18n') 47 | pkg = import('pkgconfig') 48 | python = import('python').find_installation('python3') 49 | 50 | source_root = meson.current_source_dir() 51 | 52 | data_dir = source_root / 'data' 53 | templates_dir = source_root / 'build-aux/templates' 54 | 55 | mbim_codegen = find_program(source_root / 'build-aux/mbim-codegen/mbim-codegen') 56 | mbim_mkenums = find_program(source_root / 'build-aux/mbim-mkenums') 57 | 58 | top_inc = include_directories('.') 59 | 60 | cc = meson.get_compiler('c') 61 | 62 | config_h = configuration_data() 63 | config_h.set_quoted('PACKAGE_VERSION', mbim_version) 64 | 65 | # compiler flags 66 | common_flags = ['-DHAVE_CONFIG_H'] 67 | 68 | # compiler flags that are always enabled, even in release builds 69 | cc_flags = cc.get_supported_arguments([ 70 | # warning on unused parameters is overkill, never do that 71 | '-Wno-unused-parameter', 72 | # function type cast disabled: used throughout the code especially to 73 | # cast GAsyncReadyCallbacks with the real object type instead of GObject 74 | '-Wno-cast-function-type', 75 | # all message protocol structs are packed, never complain about it 76 | '-Wno-packed', 77 | ]) 78 | 79 | # strict flags to use in debug builds 80 | if get_option('buildtype').contains('debug') 81 | cc_flags += cc.get_supported_arguments([ 82 | '-fno-strict-aliasing', 83 | '-Waggregate-return', 84 | '-Wcast-align', 85 | '-Wdeclaration-after-statement', 86 | '-Wdouble-promotion', 87 | '-Wduplicated-branches', 88 | '-Wduplicated-cond', 89 | '-Wfloat-equal', 90 | '-Wformat=2', 91 | '-Wformat-nonliteral', 92 | '-Wformat-security', 93 | '-Winit-self', 94 | '-Winline', 95 | '-Wjump-misses-init', 96 | '-Wlogical-op', 97 | '-Wnested-externs', 98 | '-Wmissing-declarations', 99 | '-Wmissing-format-attribute', 100 | '-Wmissing-include-dirs', 101 | '-Wmissing-noreturn', 102 | '-Wmissing-prototypes', 103 | '-Wnull-dereference', 104 | '-Wpointer-arith', 105 | '-Wredundant-decls', 106 | '-Wrestrict', 107 | '-Wreturn-type', 108 | '-Wshadow', 109 | '-Wstrict-prototypes', 110 | '-Wsuggest-attribute=format', 111 | '-Wswitch-default', 112 | '-Wswitch-enum', 113 | '-Wundef', 114 | '-Wunused-but-set-variable', 115 | '-Wwrite-strings', 116 | ]) 117 | endif 118 | 119 | add_project_arguments(common_flags + cc_flags, language: 'c') 120 | 121 | glib_version = '2.56' 122 | 123 | glib_dep = dependency('glib-2.0', version: '>= ' + glib_version) 124 | gio_unix_dep = dependency('gio-unix-2.0') 125 | 126 | deps = [ 127 | glib_dep, 128 | dependency('gio-2.0'), 129 | dependency('gobject-2.0'), 130 | ] 131 | 132 | c_flags = [ 133 | '-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_' + glib_version.underscorify(), 134 | '-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_' + glib_version.underscorify(), 135 | '-DGLIB_DISABLE_DEPRECATION_WARNINGS', 136 | ] 137 | 138 | glib_deps = declare_dependency( 139 | dependencies: deps, 140 | compile_args: c_flags, 141 | ) 142 | 143 | enable_bash_completion = get_option('bash_completion') 144 | if enable_bash_completion 145 | bash_completion_dep = dependency('bash-completion') 146 | bash_completion_completionsdir = bash_completion_dep.get_pkgconfig_variable( 147 | 'completionsdir', 148 | # bash-completion 2.10 changed the substitutions 149 | define_variable: bash_completion_dep.version().version_compare('>= 2.10') ? ['datadir', mbim_datadir] : ['prefix', mbim_prefix], 150 | ) 151 | endif 152 | 153 | # MBIM username 154 | mbim_username = get_option('mbim_username') 155 | enable_mbim_username = (mbim_username != '') 156 | if enable_mbim_username 157 | config_h.set_quoted('MBIM_USERNAME', mbim_username) 158 | 159 | # FIXME: udev base directory, prefix can't be overrided 160 | udev_udevdir = get_option('udevdir') 161 | if udev_udevdir == '' 162 | udev_udevdir = dependency('udev').get_pkgconfig_variable('udevdir') 163 | endif 164 | else 165 | mbim_username = 'no (root)' 166 | endif 167 | config_h.set('MBIM_USERNAME_ENABLED', enable_mbim_username) 168 | 169 | # introspection support 170 | enable_gir = get_option('introspection') 171 | if enable_gir 172 | dependency('gobject-introspection-1.0', version: '>= 0.9.6') 173 | endif 174 | 175 | version_conf = { 176 | 'MBIM_MAJOR_VERSION': mbim_major_version, 177 | 'MBIM_MINOR_VERSION': mbim_minor_version, 178 | 'MBIM_MICRO_VERSION': mbim_micro_version, 179 | 'VERSION': mbim_version, 180 | } 181 | 182 | subdir('src') 183 | subdir('utils') 184 | subdir('examples/simple-tester-c') 185 | 186 | enable_gtk_doc = get_option('gtk_doc') 187 | if enable_gtk_doc 188 | subdir('docs/reference/libmbim-glib') 189 | endif 190 | 191 | enable_man = get_option('man') 192 | if enable_man 193 | subdir('docs/man') 194 | endif 195 | 196 | enable_fuzzer = get_option('fuzzer') 197 | 198 | configure_file( 199 | output: 'config.h', 200 | configuration: config_h, 201 | ) 202 | 203 | summary({ 204 | 'compiler': cc.get_id(), 205 | 'cflags': cc_flags, 206 | 'Documentation': enable_gtk_doc, 207 | 'bash completion': enable_bash_completion, 208 | 'gobject introspection': enable_gir, 209 | 'man pages': enable_man, 210 | 'fuzzer': enable_fuzzer, 211 | }, section: 'Build') 212 | 213 | summary({ 214 | 'prefix': mbim_prefix, 215 | 'udev base directory': (enable_mbim_username ? udev_udevdir : 'disabled'), 216 | }, section: 'System paths') 217 | 218 | summary({ 219 | 'MBIM username': mbim_username, 220 | }, section: 'Features') 221 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | option('mbim_username', type: 'string', value: '', description: 'user allowed to access MBIM devices') 5 | 6 | option('udevdir', type: 'string', value: '', description: 'where udev base directory is') 7 | 8 | option('introspection', type: 'boolean', value: true, description: 'build introspection support') 9 | option('gtk_doc', type: 'boolean', value: false, description: 'use gtk-doc to build documentation') 10 | option('man', type: 'boolean', value: true, description: 'build man pages using help2man') 11 | 12 | option('bash_completion', type: 'boolean', value: true, description: 'install bash completion files') 13 | 14 | option('fuzzer', type: 'boolean', value: false, description: 'build fuzzer tests') 15 | -------------------------------------------------------------------------------- /src/common/mbim-common.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * Copyright (C) 2013 - 2014 Aleksander Morgado 5 | * Copyright (C) 2017 Google Inc. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #include "mbim-common.h" 12 | 13 | /*****************************************************************************/ 14 | 15 | gchar * 16 | mbim_common_str_hex (gconstpointer mem, 17 | gsize size, 18 | gchar delimiter) 19 | { 20 | const guint8 *data = mem; 21 | gsize i; 22 | gsize j; 23 | gsize new_str_length; 24 | gchar *new_str; 25 | 26 | /* Get new string length. If input string has N bytes, we need: 27 | * - 1 byte for last NUL char 28 | * - 2N bytes for hexadecimal char representation of each byte... 29 | * - N-1 bytes for the separator ':' 30 | * So... a total of (1+2N+N-1) = 3N bytes are needed... */ 31 | new_str_length = 3 * size; 32 | 33 | /* Allocate memory for new array and initialize contents to NUL */ 34 | new_str = g_malloc0 (new_str_length); 35 | 36 | /* Print hexadecimal representation of each byte... */ 37 | for (i = 0, j = 0; i < size; i++, j += 3) { 38 | /* Print character in output string... */ 39 | snprintf (&new_str[j], 3, "%02X", data[i]); 40 | /* And if needed, add separator */ 41 | if (i != (size - 1) ) 42 | new_str[j + 2] = delimiter; 43 | } 44 | 45 | /* Set output string */ 46 | return new_str; 47 | } 48 | -------------------------------------------------------------------------------- /src/common/mbim-common.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * Copyright (C) 2013 - 2014 Aleksander Morgado 5 | * Copyright (C) 2017 Google Inc. 6 | */ 7 | 8 | #ifndef _COMMON_MBIM_COMMON_H_ 9 | #define _COMMON_MBIM_COMMON_H_ 10 | 11 | #include 12 | 13 | gchar *mbim_common_str_hex (gconstpointer mem, 14 | gsize size, 15 | gchar delimiter); 16 | 17 | #endif /* _COMMON_MBIM_COMMON_H_ */ 18 | -------------------------------------------------------------------------------- /src/common/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | libmbim_common = static_library( 5 | 'mbim-common', 6 | sources: 'mbim-common.c', 7 | include_directories: top_inc, 8 | dependencies: glib_dep, 9 | ) 10 | 11 | libmbim_common_dep = declare_dependency( 12 | include_directories: '.', 13 | dependencies: glib_dep, 14 | link_with: libmbim_common, 15 | ) 16 | 17 | subdir('test') 18 | -------------------------------------------------------------------------------- /src/common/test/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | test_name = 'test-common' 5 | 6 | executable( 7 | test_name, 8 | sources: test_name + '.c', 9 | include_directories: top_inc, 10 | dependencies: libmbim_common_dep, 11 | ) 12 | -------------------------------------------------------------------------------- /src/common/test/test-common.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * Copyright (C) 2017 Google Inc. 5 | */ 6 | 7 | #include 8 | 9 | #include "mbim-common.h" 10 | 11 | static void 12 | test_common_str_hex (void) 13 | { 14 | static const guint8 buffer [] = { 0x00, 0xDE, 0xAD, 0xC0, 0xDE }; 15 | gchar *str; 16 | 17 | str = mbim_common_str_hex (NULL, 0, ':'); 18 | g_assert (str == NULL); 19 | 20 | str = mbim_common_str_hex (buffer, 0, ':'); 21 | g_assert (str == NULL); 22 | 23 | str = mbim_common_str_hex (buffer, 1, ':'); 24 | g_assert_cmpstr (str, ==, "00"); 25 | g_free (str); 26 | 27 | str = mbim_common_str_hex (buffer, 2, '-'); 28 | g_assert_cmpstr (str, ==, "00-DE"); 29 | g_free (str); 30 | 31 | str = mbim_common_str_hex (buffer, 5, '.'); 32 | g_assert_cmpstr (str, ==, "00.DE.AD.C0.DE"); 33 | g_free (str); 34 | } 35 | 36 | /*****************************************************************************/ 37 | 38 | int main (int argc, char **argv) 39 | { 40 | g_test_init (&argc, &argv, NULL); 41 | 42 | g_test_add_func ("/common/str_hex", test_common_str_hex); 43 | 44 | return g_test_run (); 45 | } 46 | -------------------------------------------------------------------------------- /src/libmbim-glib/76-mbim-device-ownership.rules.in: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | 3 | # do not edit this file, it will be overwritten on update 4 | 5 | ACTION!="add|change|move", GOTO="mbim_device_ownership_end" 6 | 7 | KERNEL=="cdc-wdm*", DRIVERS=="cdc_mbim", SUBSYSTEM=="usbmisc", OWNER="@MBIM_USERNAME@" 8 | 9 | LABEL="mbim_device_ownership_end" 10 | -------------------------------------------------------------------------------- /src/libmbim-glib/generated/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | generated_inc = include_directories('.') 5 | 6 | gen_sources = [] 7 | gen_headers = [] 8 | gen_sections = [] 9 | gen_sections_deps = [] 10 | 11 | # Error types 12 | enum_types = 'mbim-error-types' 13 | 14 | gen_headers += custom_target( 15 | enum_types + '.h', 16 | input: mbim_errors_header, 17 | output: enum_types + '.h', 18 | command: [ 19 | python, 20 | mbim_mkenums, 21 | '--fhead', '#ifndef __LIBMBIM_GLIB_ERROR_TYPES_H__\n#define __LIBMBIM_GLIB_ERROR_TYPES_H__\n#include "mbim-errors.h"\n', 22 | '--template', files(templates_dir / enum_types + '.h.template'), 23 | '--ftail', '#endif /* __LIBMBIM_GLIB_ERROR_TYPES_H__ */\n', 24 | '@INPUT@'], 25 | capture: true, 26 | install: true, 27 | install_dir: mbim_glib_pkgincludedir, 28 | ) 29 | 30 | gen_sources += custom_target( 31 | enum_types + '.c', 32 | input: mbim_errors_header, 33 | output: enum_types + '.c', 34 | command: [ 35 | python, 36 | mbim_mkenums, 37 | '--fhead', '#include "mbim-errors.h"\n#include "mbim-error-types.h"\n', 38 | '--template', files(templates_dir / enum_types + '.c.template'), 39 | '@INPUT@'], 40 | capture: true, 41 | ) 42 | 43 | enum_types = 'mbim-error-quarks' 44 | 45 | gen_sources += custom_target( 46 | enum_types + '.c', 47 | input: mbim_errors_header, 48 | output: enum_types + '.c', 49 | command: [ 50 | python, 51 | mbim_mkenums, 52 | '--fhead', '#include "mbim-errors.h"\n#include "mbim-error-types.h"\n', 53 | '--template', files(templates_dir / enum_types + '.c.template'), 54 | '@INPUT@'], 55 | capture: true, 56 | ) 57 | 58 | # Enum types 59 | enum_types = 'mbim-enum-types' 60 | 61 | gen_headers += custom_target( 62 | enum_types + '.h', 63 | input: mbim_enums_headers, 64 | output: enum_types + '.h', 65 | command: [ 66 | python, 67 | mbim_mkenums, 68 | '--enums-only', 69 | '--fhead', '#ifndef __LIBMBIM_GLIB_ENUM_TYPES_H__\n#define __LIBMBIM_GLIB_ENUM_TYPES_H__\n#include "mbim-uuid.h"\n#include "mbim-cid.h"\n#include "mbim-message.h"\n#include "mbim-enums.h"\n#include "mbim-tlv.h"\n', 70 | '--template', files(templates_dir / enum_types + '.h.template'), 71 | '--ftail', '#endif /* __LIBMBIM_GLIB_ENUM_TYPES_H__ */\n', 72 | '@INPUT@'], 73 | capture: true, 74 | install: true, 75 | install_dir: mbim_glib_pkgincludedir, 76 | ) 77 | 78 | gen_sources += custom_target( 79 | enum_types + '.c', 80 | input: mbim_enums_headers, 81 | output: enum_types + '.c', 82 | command: [ 83 | python, 84 | mbim_mkenums, 85 | '--enums-only', 86 | '--fhead', '#include "mbim-enum-types.h"\n', 87 | '--template', files(templates_dir / enum_types + '.c.template'), 88 | '@INPUT@'], 89 | capture: true, 90 | ) 91 | 92 | # Flag types 93 | enum_types = 'mbim-flag-types' 94 | 95 | gen_headers += custom_target( 96 | enum_types + '.h', 97 | input: mbim_enums_headers, 98 | output: enum_types + '.h', 99 | command: [ 100 | python, 101 | mbim_mkenums, 102 | '--flags-only', 103 | '--fhead', '#ifndef __LIBMBIM_GLIB_FLAG_TYPES_H__\n#define __LIBMBIM_GLIB_FLAG_TYPES_H__\n#include "mbim-uuid.h"\n#include "mbim-cid.h"\n#include "mbim-message.h"\n#include "mbim-enums.h"\n#include "mbim-tlv.h"\n', 104 | '--template', files(templates_dir / enum_types + '.h.template'), 105 | '--ftail', '#endif /* __LIBMBIM_GLIB_FLAG_TYPES_H__ */\n', 106 | '@INPUT@'], 107 | capture: true, 108 | install: true, 109 | install_dir: mbim_glib_pkgincludedir, 110 | ) 111 | 112 | gen_sources += custom_target( 113 | enum_types + '.c', 114 | input: mbim_enums_headers, 115 | output: enum_types + '.c', 116 | command: [ 117 | python, 118 | mbim_mkenums, 119 | '--flags-only', 120 | '--fhead', '#include "mbim-flag-types.h"\n', 121 | '--template', files(templates_dir / enum_types + '.c.template'), 122 | '@INPUT@'], 123 | capture: true, 124 | ) 125 | 126 | services_data = [ 127 | ['atds'], 128 | ['auth'], 129 | ['basic-connect', 'ms-basic-connect-v2', 'ms-basic-connect-v3'], 130 | ['dss'], 131 | ['intel-firmware-update', 'intel-firmware-update-v2'], 132 | ['intel-thermal-rf'], 133 | ['ms-basic-connect-extensions', 'ms-basic-connect-extensions-v2', 'ms-basic-connect-extensions-v3'], 134 | ['ms-uicc-low-level-access'], 135 | ['ms-firmware-id'], 136 | ['ms-host-shutdown'], 137 | ['ms-sar'], 138 | ['ms-voice-extensions'], 139 | ['phonebook'], 140 | ['proxy-control'], 141 | ['qdu'], 142 | ['quectel'], 143 | ['qmi'], 144 | ['sms'], 145 | ['stk'], 146 | ['ussd'], 147 | ['intel-mutual-authentication'], 148 | ['intel-tools'], 149 | ['google'], 150 | ['fibocom'], 151 | ['compal'], 152 | ['intel-at-tunnel'], 153 | ] 154 | 155 | foreach service_data: services_data 156 | service = service_data[0] 157 | name = 'mbim-' + service 158 | 159 | input = [] 160 | foreach service_file: service_data 161 | input += data_dir / 'mbim-service-@0@.json'.format(service_file) 162 | endforeach 163 | 164 | generated = custom_target( 165 | name, 166 | input: input, 167 | output: [name + '.c', name + '.h', name + '.sections'], 168 | command: [mbim_codegen, '--output', '@OUTDIR@' / name, '@INPUT@'], 169 | install: true, 170 | install_dir: [false, mbim_glib_pkgincludedir, false], 171 | ) 172 | 173 | gen_sources += generated[0] 174 | gen_headers += generated[1] 175 | 176 | # FIXME: the third target generated by custom target can't by used because is not a known 177 | # source file, to the path has to be used. the first workaround is to use the 178 | # build paths to point to the files, and the second workaround is to use 179 | # custom target objects to force its building. 180 | gen_sections += [meson.current_build_dir() / name + '.sections'] 181 | gen_sections_deps += [generated] 182 | endforeach 183 | 184 | c_flags = [ 185 | '-DLIBMBIM_GLIB_COMPILATION', 186 | '-DG_LOG_DOMAIN="Mbim"', 187 | '-Wno-unused-function', 188 | ] 189 | 190 | libmbim_glib_generated = static_library( 191 | 'mbim-glib-generated', 192 | sources: gen_sources + gen_headers, 193 | include_directories: libmbim_glib_inc, 194 | dependencies: glib_deps, 195 | c_args: c_flags, 196 | ) 197 | 198 | generated_dep = declare_dependency( 199 | sources: gen_headers, 200 | include_directories: [libmbim_glib_inc, generated_inc], 201 | dependencies: glib_deps, 202 | ) 203 | -------------------------------------------------------------------------------- /src/libmbim-glib/kernel/if_link.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _MBIM_IF_LINK_H 3 | #define _MBIM_IF_LINK_H 4 | 5 | #include 6 | 7 | /* Instead of checking if the libc or kernel provided headers 8 | * include the enum value we require, in this case we define 9 | * a new one ourselves. We cannot check if a single enum value 10 | * was defined in an included header via preprocessor directives. 11 | */ 12 | 13 | enum { 14 | /* device (sysfs) name as parent, used instead 15 | * of IFLA_LINK where there's no parent netdev. 16 | */ 17 | MBIM_IFLA_PARENT_DEV_NAME = 56, 18 | }; 19 | 20 | #endif /* _MBIM_IF_LINK_H */ 21 | -------------------------------------------------------------------------------- /src/libmbim-glib/kernel/wwan.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _MBIM_WWAN_H 3 | #define _MBIM_WWAN_H 4 | 5 | /* kernel values defined in linux/wwan.h */ 6 | enum { 7 | MBIM_IFLA_WWAN_UNSPEC, 8 | MBIM_IFLA_WWAN_LINK_ID, /* u32 */ 9 | }; 10 | 11 | #endif /* _MBIM_WWAN_H */ 12 | -------------------------------------------------------------------------------- /src/libmbim-glib/libmbim-glib.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * libmbim-glib -- GLib/GIO based library to control MBIM devices 5 | * 6 | * Copyright (C) 2013 - 2014 Aleksander Morgado 7 | * Copyright (C) 2022 Intel Corporation 8 | */ 9 | 10 | #ifndef _LIBMBIM_GLIB_H_ 11 | #define _LIBMBIM_GLIB_H_ 12 | 13 | #define __LIBMBIM_GLIB_H_INSIDE__ 14 | 15 | /* libmbim-glib headers */ 16 | 17 | #include "mbim-version.h" 18 | #include "mbim-utils.h" 19 | #include "mbim-uuid.h" 20 | #include "mbim-cid.h" 21 | #include "mbim-message.h" 22 | #include "mbim-device.h" 23 | #include "mbim-enums.h" 24 | #include "mbim-proxy.h" 25 | #include "mbim-tlv.h" 26 | 27 | /* generated */ 28 | #include "mbim-enum-types.h" 29 | #include "mbim-flag-types.h" 30 | #include "mbim-error-types.h" 31 | #include "mbim-basic-connect.h" 32 | #include "mbim-sms.h" 33 | #include "mbim-ussd.h" 34 | #include "mbim-auth.h" 35 | #include "mbim-phonebook.h" 36 | #include "mbim-stk.h" 37 | #include "mbim-dss.h" 38 | #include "mbim-ms-firmware-id.h" 39 | #include "mbim-ms-host-shutdown.h" 40 | #include "mbim-ms-sar.h" 41 | #include "mbim-qmi.h" 42 | #include "mbim-atds.h" 43 | #include "mbim-qdu.h" 44 | #include "mbim-intel-firmware-update.h" 45 | #include "mbim-ms-basic-connect-extensions.h" 46 | #include "mbim-ms-uicc-low-level-access.h" 47 | #include "mbim-quectel.h" 48 | #include "mbim-intel-thermal-rf.h" 49 | #include "mbim-ms-voice-extensions.h" 50 | #include "mbim-intel-mutual-authentication.h" 51 | #include "mbim-intel-tools.h" 52 | #include "mbim-google.h" 53 | #include "mbim-fibocom.h" 54 | #include "mbim-compal.h" 55 | #include "mbim-intel-at-tunnel.h" 56 | 57 | /* backwards compatibility */ 58 | #include "mbim-compat.h" 59 | 60 | #endif /* _LIBMBIM_GLIB_H_ */ 61 | -------------------------------------------------------------------------------- /src/libmbim-glib/mbim-compat.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * Copyright (C) 2014 Aleksander Morgado 5 | */ 6 | 7 | #include "mbim-compat.h" 8 | 9 | #ifndef MBIM_DISABLE_DEPRECATED 10 | 11 | /*****************************************************************************/ 12 | /* 'Service Subscriber List' rename to 'Service Subscribe List' */ 13 | 14 | MbimMessage * 15 | mbim_message_device_service_subscriber_list_set_new ( 16 | guint32 events_count, 17 | const MbimEventEntry *const *events, 18 | GError **error) 19 | { 20 | return (mbim_message_device_service_subscribe_list_set_new ( 21 | events_count, 22 | events, 23 | error)); 24 | } 25 | 26 | gboolean 27 | mbim_message_device_service_subscriber_list_response_parse ( 28 | const MbimMessage *message, 29 | guint32 *events_count, 30 | MbimEventEntry ***events, 31 | GError **error) 32 | { 33 | return (mbim_message_device_service_subscribe_list_response_parse ( 34 | message, 35 | events_count, 36 | events, 37 | error)); 38 | } 39 | 40 | /*****************************************************************************/ 41 | /* 'LTE Attach Status' rename to 'LTE Attach Info', to avoid the unneeded 42 | * MbimLteAttachStatus struct */ 43 | 44 | void 45 | mbim_lte_attach_status_free (MbimDeprecatedLteAttachStatus *var) 46 | { 47 | if (!var) 48 | return; 49 | 50 | g_free (var->access_string); 51 | g_free (var->user_name); 52 | g_free (var->password); 53 | g_free (var); 54 | } 55 | 56 | MbimMessage * 57 | mbim_message_ms_basic_connect_extensions_lte_attach_status_query_new (GError **error) 58 | { 59 | return mbim_message_ms_basic_connect_extensions_lte_attach_info_query_new (error); 60 | } 61 | 62 | gboolean 63 | mbim_message_ms_basic_connect_extensions_lte_attach_status_response_parse ( 64 | const MbimMessage *message, 65 | MbimDeprecatedLteAttachStatus **out_lte_attach_status, 66 | GError **error) 67 | { 68 | g_autoptr(MbimLteAttachStatus) var = NULL; 69 | 70 | var = g_new0 (MbimDeprecatedLteAttachStatus, 1); 71 | if (!mbim_message_ms_basic_connect_extensions_lte_attach_info_response_parse ( 72 | message, 73 | &var->lte_attach_state, 74 | &var->ip_type, 75 | &var->access_string, 76 | &var->user_name, 77 | &var->password, 78 | &var->compression, 79 | &var->auth_protocol, 80 | error)) 81 | return FALSE; 82 | 83 | *out_lte_attach_status = g_steal_pointer (&var); 84 | return TRUE; 85 | } 86 | 87 | gboolean 88 | mbim_message_ms_basic_connect_extensions_lte_attach_status_notification_parse ( 89 | const MbimMessage *message, 90 | MbimDeprecatedLteAttachStatus **out_lte_attach_status, 91 | GError **error) 92 | { 93 | g_autoptr(MbimLteAttachStatus) var = NULL; 94 | 95 | var = g_new0 (MbimDeprecatedLteAttachStatus, 1); 96 | if (!mbim_message_ms_basic_connect_extensions_lte_attach_info_notification_parse ( 97 | message, 98 | &var->lte_attach_state, 99 | &var->ip_type, 100 | &var->access_string, 101 | &var->user_name, 102 | &var->password, 103 | &var->compression, 104 | &var->auth_protocol, 105 | error)) 106 | return FALSE; 107 | 108 | *out_lte_attach_status = g_steal_pointer (&var); 109 | return TRUE; 110 | } 111 | 112 | /*****************************************************************************/ 113 | /* MbimSmsStatusFlag is flags, not an enum */ 114 | 115 | const gchar * 116 | mbim_sms_status_flag_get_string (MbimSmsStatusFlag val) 117 | { 118 | const gchar *sms_status_flag_values[] = { 119 | [MBIM_SMS_STATUS_FLAG_NONE] = "none", 120 | [MBIM_SMS_STATUS_FLAG_MESSAGE_STORE_FULL] = "message-store-full", 121 | [MBIM_SMS_STATUS_FLAG_NEW_MESSAGE] = "new-message", 122 | }; 123 | 124 | return ((guint)val < G_N_ELEMENTS (sms_status_flag_values)) ? sms_status_flag_values[val] : NULL; 125 | } 126 | 127 | #endif /* MBIM_DISABLE_DEPRECATED */ 128 | -------------------------------------------------------------------------------- /src/libmbim-glib/mbim-helpers-netlink.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * libmbim-glib -- GLib/GIO based library to control MBIM devices 5 | * 6 | * Copyright (C) 2022 Daniele Palmas 7 | * 8 | * Based on previous work: 9 | * Copyright (C) 2020-2021 Eric Caruso 10 | * Copyright (C) 2020-2021 Andrew Lassalle 11 | * Copyright (C) 2021 Aleksander Morgado 12 | */ 13 | 14 | #ifndef _LIBMBIM_GLIB_MBIM_HELPERS_NETLINK_H_ 15 | #define _LIBMBIM_GLIB_MBIM_HELPERS_NETLINK_H_ 16 | 17 | #if !defined (LIBMBIM_GLIB_COMPILATION) 18 | #error "This is a private header!!" 19 | #endif 20 | 21 | #include 22 | #include 23 | 24 | G_BEGIN_DECLS 25 | 26 | typedef GByteArray NetlinkMessage; 27 | 28 | typedef struct { 29 | struct nlmsghdr msghdr; 30 | struct ifinfomsg ifreq; 31 | } NetlinkHeader; 32 | 33 | G_GNUC_INTERNAL 34 | NetlinkHeader *mbim_helpers_netlink_get_message_header (NetlinkMessage *msg); 35 | 36 | G_GNUC_INTERNAL 37 | guint mbim_helpers_netlink_get_pos_of_next_attr (NetlinkMessage *msg); 38 | 39 | G_GNUC_INTERNAL 40 | void mbim_helpers_netlink_append_attribute_nested (NetlinkMessage *msg, 41 | gushort type); 42 | 43 | G_GNUC_INTERNAL 44 | void mbim_helpers_netlink_append_attribute_string (NetlinkMessage *msg, 45 | gushort type, 46 | const gchar *value); 47 | 48 | G_GNUC_INTERNAL 49 | void mbim_helpers_netlink_append_attribute_string_null (NetlinkMessage *msg, 50 | gushort type, 51 | const gchar *value); 52 | 53 | G_GNUC_INTERNAL 54 | void mbim_helpers_netlink_append_attribute_uint16 (NetlinkMessage *msg, 55 | gushort type, 56 | guint16 value); 57 | 58 | G_GNUC_INTERNAL 59 | void mbim_helpers_netlink_append_attribute_uint32 (NetlinkMessage *msg, 60 | gushort type, 61 | guint32 value); 62 | 63 | G_GNUC_INTERNAL 64 | NetlinkMessage *mbim_helpers_netlink_message_new (guint16 type, 65 | guint16 extra_flags); 66 | 67 | G_GNUC_INTERNAL 68 | void mbim_helpers_netlink_message_free (NetlinkMessage *msg); 69 | 70 | typedef struct { 71 | guint32 sequence_id; 72 | GSource *timeout_source; 73 | GTask *completion_task; 74 | } NetlinkTransaction; 75 | 76 | G_GNUC_INTERNAL 77 | void mbim_helpers_netlink_transaction_complete_with_error (NetlinkTransaction *tr, 78 | GHashTable *transactions, 79 | GError *error); 80 | 81 | G_GNUC_INTERNAL 82 | void mbim_helpers_netlink_transaction_complete (NetlinkTransaction *tr, 83 | GHashTable *transactions, 84 | gint saved_errno); 85 | 86 | G_GNUC_INTERNAL 87 | void mbim_helpers_netlink_transaction_free (NetlinkTransaction *tr); 88 | 89 | G_GNUC_INTERNAL 90 | NetlinkTransaction *mbim_helpers_netlink_transaction_new (guint *sequence_id, 91 | GHashTable *transactions, 92 | NetlinkMessage *msg, 93 | guint timeout, 94 | GTask *task); 95 | 96 | G_GNUC_INTERNAL 97 | void mbim_helpers_netlink_set_callback (GSource **source, 98 | GSocket *socket, 99 | GHashTable *transactions); 100 | 101 | G_END_DECLS 102 | 103 | #endif /* _LIBMBIM_GLIB_MBIM_HELPERS_NETLINK_H_ */ 104 | -------------------------------------------------------------------------------- /src/libmbim-glib/mbim-helpers.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * libmbim-glib -- GLib/GIO based library to control MBIM devices 5 | * 6 | * Copyright (C) 2013 - 2021 Aleksander Morgado 7 | */ 8 | 9 | #ifndef _LIBMBIM_GLIB_MBIM_HELPERS_H_ 10 | #define _LIBMBIM_GLIB_MBIM_HELPERS_H_ 11 | 12 | #if !defined (LIBMBIM_GLIB_COMPILATION) 13 | #error "This is a private header!!" 14 | #endif 15 | 16 | #include 17 | #include 18 | 19 | G_BEGIN_DECLS 20 | 21 | /******************************************************************************/ 22 | /* Helpers to read variables from a bytearray without assuming alignment. The 23 | * caller should ensure the buffer contains the required amount of bytes in each 24 | * case. */ 25 | 26 | G_GNUC_INTERNAL 27 | guint16 mbim_helpers_read_unaligned_guint16 (const guint8 *buffer); 28 | G_GNUC_INTERNAL 29 | guint32 mbim_helpers_read_unaligned_guint32 (const guint8 *buffer); 30 | G_GNUC_INTERNAL 31 | guint32 mbim_helpers_read_unaligned_gint32 (const guint8 *buffer); 32 | G_GNUC_INTERNAL 33 | guint64 mbim_helpers_read_unaligned_guint64 (const guint8 *buffer); 34 | 35 | /******************************************************************************/ 36 | 37 | G_GNUC_INTERNAL 38 | gboolean mbim_helpers_check_user_allowed (uid_t uid, 39 | GError **error); 40 | 41 | G_GNUC_INTERNAL 42 | gchar *mbim_helpers_get_devpath (const gchar *cdc_wdm_path, 43 | GError **error); 44 | 45 | G_GNUC_INTERNAL 46 | gchar *mbim_helpers_get_devname (const gchar *cdc_wdm_path, 47 | GError **error); 48 | 49 | G_GNUC_INTERNAL 50 | gboolean mbim_helpers_list_links_wdm (GFile *sysfs_file, 51 | GCancellable *cancellable, 52 | GPtrArray *previous_links, 53 | GPtrArray **out_links, 54 | GError **error); 55 | 56 | G_GNUC_INTERNAL 57 | gboolean mbim_helpers_list_links_wwan (const gchar *base_ifname, 58 | GFile *sysfs_file, 59 | GCancellable *cancellable, 60 | GPtrArray *previous_links, 61 | GPtrArray **out_links, 62 | GError **error); 63 | 64 | G_END_DECLS 65 | 66 | #endif /* _LIBMBIM_GLIB_MBIM_HELPERS_H_ */ 67 | -------------------------------------------------------------------------------- /src/libmbim-glib/mbim-net-port-manager-wdm.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * libmbim-glib -- GLib/GIO based library to control MBIM devices 5 | * 6 | * Copyright (C) 2022 Daniele Palmas 7 | * 8 | * Based on previous work: 9 | * Copyright (C) 2020-2021 Eric Caruso 10 | * Copyright (C) 2020-2021 Andrew Lassalle 11 | * Copyright (C) 2021 Aleksander Morgado 12 | */ 13 | 14 | #ifndef _LIBMBIM_GLIB_MBIM_NET_PORT_MANAGER_WDM_H_ 15 | #define _LIBMBIM_GLIB_MBIM_NET_PORT_MANAGER_WDM_H_ 16 | 17 | #include 18 | #include 19 | 20 | #define MBIM_TYPE_NET_PORT_MANAGER_WDM (mbim_net_port_manager_wdm_get_type ()) 21 | #define MBIM_NET_PORT_MANAGER_WDM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MBIM_TYPE_NET_PORT_MANAGER_WDM, MbimNetPortManagerWdm)) 22 | #define MBIM_NET_PORT_MANAGER_WDM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MBIM_TYPE_NET_PORT_MANAGER_WDM, MbimNetPortManagerWdmClass)) 23 | #define MBIM_IS_NET_PORT_MANAGER_WDM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MBIM_TYPE_NET_PORT_MANAGER_WDM)) 24 | #define MBIM_IS_NET_PORT_MANAGER_WDM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MBIM_TYPE_NET_PORT_MANAGER_WDM)) 25 | #define MBIM_NET_PORT_MANAGER_WDM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MBIM_TYPE_NET_PORT_MANAGER_WDM, MbimNetPortManagerWdmClass)) 26 | 27 | typedef struct _MbimNetPortManagerWdm MbimNetPortManagerWdm; 28 | typedef struct _MbimNetPortManagerWdmClass MbimNetPortManagerWdmClass; 29 | 30 | struct _MbimNetPortManagerWdm { 31 | MbimNetPortManager parent; 32 | }; 33 | 34 | struct _MbimNetPortManagerWdmClass { 35 | MbimNetPortManagerClass parent; 36 | }; 37 | 38 | GType mbim_net_port_manager_wdm_get_type (void); 39 | G_DEFINE_AUTOPTR_CLEANUP_FUNC (MbimNetPortManagerWdm, g_object_unref) 40 | 41 | MbimNetPortManagerWdm *mbim_net_port_manager_wdm_new (const gchar *iface, 42 | GError **error); 43 | 44 | #endif /* _LIBMBIM_GLIB_MBIM_NET_PORT_MANAGER_WDM_H_ */ 45 | -------------------------------------------------------------------------------- /src/libmbim-glib/mbim-net-port-manager-wwan.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * libmbim-glib -- GLib/GIO based library to control MBIM devices 5 | * 6 | * Copyright (C) 2022 Daniele Palmas 7 | * 8 | * Based on previous work: 9 | * Copyright (C) 2020-2021 Eric Caruso 10 | * Copyright (C) 2020-2021 Andrew Lassalle 11 | * Copyright (C) 2021 Aleksander Morgado 12 | */ 13 | 14 | #ifndef _LIBMBIM_GLIB_MBIM_NET_PORT_MANAGER_WWAN_H_ 15 | #define _LIBMBIM_GLIB_MBIM_NET_PORT_MANAGER_WWAN_H_ 16 | 17 | #include 18 | #include 19 | 20 | #define MBIM_TYPE_NET_PORT_MANAGER_WWAN (mbim_net_port_manager_wwan_get_type ()) 21 | #define MBIM_NET_PORT_MANAGER_WWAN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MBIM_TYPE_NET_PORT_MANAGER_WWAN, MbimNetPortManagerWwan)) 22 | #define MBIM_NET_PORT_MANAGER_WWAN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MBIM_TYPE_NET_PORT_MANAGER_WWAN, MbimNetPortManagerWwanClass)) 23 | #define MBIM_IS_NET_PORT_MANAGER_WWAN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MBIM_TYPE_NET_PORT_MANAGER_WWAN)) 24 | #define MBIM_IS_NET_PORT_MANAGER_WWAN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MBIM_TYPE_NET_PORT_MANAGER_WWAN)) 25 | #define MBIM_NET_PORT_MANAGER_WWAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MBIM_TYPE_NET_PORT_MANAGER_WWAN, MbimNetPortManagerWwanClass)) 26 | 27 | typedef struct _MbimNetPortManagerWwan MbimNetPortManagerWwan; 28 | typedef struct _MbimNetPortManagerWwanClass MbimNetPortManagerWwanClass; 29 | 30 | struct _MbimNetPortManagerWwan { 31 | MbimNetPortManager parent; 32 | }; 33 | 34 | struct _MbimNetPortManagerWwanClass { 35 | MbimNetPortManagerClass parent; 36 | }; 37 | 38 | GType mbim_net_port_manager_wwan_get_type (void); 39 | G_DEFINE_AUTOPTR_CLEANUP_FUNC (MbimNetPortManagerWwan, g_object_unref) 40 | 41 | MbimNetPortManagerWwan *mbim_net_port_manager_wwan_new (GError **error); 42 | 43 | #endif /* _LIBMBIM_GLIB_MBIM_NET_PORT_MANAGER_WWAN_H_ */ 44 | -------------------------------------------------------------------------------- /src/libmbim-glib/mbim-proxy-helpers.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * libmbim-glib -- GLib/GIO based library to control MBIM devices 5 | * 6 | * Copyright (C) 2014 Aleksander Morgado 7 | * Copyright (C) 2014 Smith Micro Software, Inc. 8 | * 9 | * This is a private non-installed header 10 | */ 11 | 12 | #ifndef _LIBMBIM_GLIB_MBIM_PROXY_HELPERS_H_ 13 | #define _LIBMBIM_GLIB_MBIM_PROXY_HELPERS_H_ 14 | 15 | #if !defined (LIBMBIM_GLIB_COMPILATION) 16 | #error "This is a private header!!" 17 | #endif 18 | 19 | #include 20 | 21 | #include "mbim-basic-connect.h" 22 | 23 | G_BEGIN_DECLS 24 | 25 | gboolean _mbim_proxy_helper_service_subscribe_list_cmp (const MbimEventEntry * const *a, 26 | gsize a_size, 27 | const MbimEventEntry * const *b, 28 | gsize b_size); 29 | void _mbim_proxy_helper_service_subscribe_list_debug (const MbimEventEntry * const *list, 30 | gsize list_size); 31 | MbimEventEntry **_mbim_proxy_helper_service_subscribe_request_parse (MbimMessage *message, 32 | gsize *out_size, 33 | GError **error); 34 | MbimEventEntry **_mbim_proxy_helper_service_subscribe_list_merge (MbimEventEntry **original, 35 | gsize original_size, 36 | MbimEventEntry **merge, 37 | gsize merge_size, 38 | gsize *out_size); 39 | MbimEventEntry **_mbim_proxy_helper_service_subscribe_list_dup (MbimEventEntry **original, 40 | gsize original_size, 41 | gsize *out_size); 42 | MbimEventEntry **_mbim_proxy_helper_service_subscribe_list_new_standard (gsize *out_size); 43 | 44 | G_END_DECLS 45 | 46 | #endif /* _LIBMBIM_GLIB_MBIM_PROXY_HELPERS_H_ */ 47 | -------------------------------------------------------------------------------- /src/libmbim-glib/mbim-proxy.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * libmbim-glib -- GLib/GIO based library to control MBIM devices 5 | * 6 | * Copyright (C) 2014 Aleksander Morgado 7 | * Copyright (C) 2014 Smith Micro Software, Inc. 8 | */ 9 | 10 | #ifndef MBIM_PROXY_H 11 | #define MBIM_PROXY_H 12 | 13 | #if !defined (__LIBMBIM_GLIB_H_INSIDE__) && !defined (LIBMBIM_GLIB_COMPILATION) 14 | #error "Only can be included directly." 15 | #endif 16 | 17 | #include 18 | #include 19 | 20 | G_BEGIN_DECLS 21 | 22 | /** 23 | * SECTION:mbim-proxy 24 | * @title: MbimProxy 25 | * @short_description: MBIM proxy handling routines 26 | * 27 | * The #MbimProxy will setup an abstract socket listening on a predefined 28 | * address, and will take care of synchronizing the access to a set of shared 29 | * MBIM ports. 30 | * 31 | * Multiple #MbimDevice objects may be connected to the #MbimProxy at any given 32 | * time. The #MbimProxy acts as a stateful proxy (all remote #MbimDevice objects 33 | * will need to share the same message sequence). 34 | */ 35 | 36 | #define MBIM_TYPE_PROXY (mbim_proxy_get_type ()) 37 | #define MBIM_PROXY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MBIM_TYPE_PROXY, MbimProxy)) 38 | #define MBIM_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MBIM_TYPE_PROXY, MbimProxyClass)) 39 | #define MBIM_IS_PROXY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MBIM_TYPE_PROXY)) 40 | #define MBIM_IS_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), MBIM_TYPE_PROXY)) 41 | #define MBIM_PROXY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MBIM_TYPE_PROXY, MbimProxyClass)) 42 | 43 | typedef struct _MbimProxy MbimProxy; 44 | typedef struct _MbimProxyClass MbimProxyClass; 45 | typedef struct _MbimProxyPrivate MbimProxyPrivate; 46 | 47 | /** 48 | * MBIM_PROXY_SOCKET_PATH: 49 | * 50 | * Symbol defining the default abstract socket name where the #MbimProxy will listen. 51 | * 52 | * Since: 1.10 53 | */ 54 | #define MBIM_PROXY_SOCKET_PATH "mbim-proxy" 55 | 56 | /** 57 | * MBIM_PROXY_N_CLIENTS: 58 | * 59 | * Symbol defining the #MbimProxy:mbim-proxy-n-clients property. 60 | * 61 | * Since: 1.10 62 | */ 63 | #define MBIM_PROXY_N_CLIENTS "mbim-proxy-n-clients" 64 | 65 | /** 66 | * MBIM_PROXY_N_DEVICES: 67 | * 68 | * Symbol defining the #MbimProxy:mbim-proxy-n-devices property. 69 | * 70 | * Since: 1.10 71 | */ 72 | #define MBIM_PROXY_N_DEVICES "mbim-proxy-n-devices" 73 | 74 | /** 75 | * MbimProxy: 76 | * 77 | * The #MbimProxy structure contains private data and should only be accessed 78 | * using the provided API. 79 | * 80 | * Since: 1.10 81 | */ 82 | struct _MbimProxy { 83 | GObject parent; 84 | MbimProxyPrivate *priv; 85 | }; 86 | 87 | struct _MbimProxyClass { 88 | GObjectClass parent; 89 | }; 90 | 91 | GType mbim_proxy_get_type (void); 92 | G_DEFINE_AUTOPTR_CLEANUP_FUNC (MbimProxy, g_object_unref) 93 | 94 | /** 95 | * mbim_proxy_new: 96 | * @error: Return location for error or %NULL. 97 | * 98 | * Creates a #MbimProxy object. 99 | * 100 | * Returns: (transfer full): a newly created #MbimProxy, or #NULL if @error is set. 101 | * 102 | * Since: 1.10 103 | */ 104 | MbimProxy *mbim_proxy_new (GError **error); 105 | 106 | /** 107 | * mbim_proxy_get_n_clients: (skip) 108 | * @self: a #MbimProxy. 109 | * 110 | * Get the number of clients currently connected to the proxy. 111 | * 112 | * Returns: a #guint. 113 | * 114 | * Since: 1.10 115 | */ 116 | guint mbim_proxy_get_n_clients (MbimProxy *self); 117 | 118 | /** 119 | * mbim_proxy_get_n_devices: (skip) 120 | * @self: a #MbimProxy. 121 | * 122 | * Get the number of devices currently connected to the proxy. 123 | * 124 | * Returns: a #guint. 125 | * 126 | * Since: 1.10 127 | */ 128 | guint mbim_proxy_get_n_devices (MbimProxy *self); 129 | 130 | G_END_DECLS 131 | 132 | #endif /* MBIM_PROXY_H */ 133 | -------------------------------------------------------------------------------- /src/libmbim-glib/mbim-tlv-private.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * libmbim-glib -- GLib/GIO based library to control MBIM devices 5 | * 6 | * Copyright (C) 2021 Aleksander Morgado 7 | * Copyright (C) 2021 Intel Corporation 8 | * 9 | * This is a private non-installed header 10 | */ 11 | 12 | #ifndef _LIBMBIM_GLIB_MBIM_TLV_PRIVATE_H_ 13 | #define _LIBMBIM_GLIB_MBIM_TLV_PRIVATE_H_ 14 | 15 | #if !defined (LIBMBIM_GLIB_COMPILATION) 16 | #error "This is a private header!!" 17 | #endif 18 | 19 | #include 20 | 21 | #include "mbim-tlv.h" 22 | 23 | G_BEGIN_DECLS 24 | 25 | /*****************************************************************************/ 26 | /* The MbimTlv */ 27 | 28 | /* Defined in the same way as GByteArray */ 29 | struct _MbimTlv { 30 | /*< private >*/ 31 | guint8 *data; 32 | guint len; 33 | }; 34 | 35 | struct tlv { 36 | guint16 type; 37 | guint8 reserved; 38 | guint8 padding_length; 39 | guint32 data_length; 40 | guint8 data[]; 41 | } __attribute__((packed)); 42 | 43 | #define MBIM_TLV_HEADER(self) ((struct tlv *)(((MbimTlv *)self)->data)) 44 | 45 | #define MBIM_TLV_FIELD_TYPE(self) MBIM_TLV_HEADER (self)->type 46 | #define MBIM_TLV_FIELD_RESERVED(self) MBIM_TLV_HEADER (self)->reserved 47 | #define MBIM_TLV_FIELD_PADDING_LENGTH(self) MBIM_TLV_HEADER (self)->padding_length 48 | #define MBIM_TLV_FIELD_DATA_LENGTH(self) MBIM_TLV_HEADER (self)->data_length 49 | #define MBIM_TLV_FIELD_DATA(self) MBIM_TLV_HEADER (self)->data 50 | 51 | #define MBIM_TLV_GET_TLV_TYPE(self) (MbimTlvType) GUINT16_FROM_LE (MBIM_TLV_FIELD_TYPE (self)) 52 | #define MBIM_TLV_GET_DATA_LENGTH(self) GUINT32_FROM_LE (MBIM_TLV_FIELD_DATA_LENGTH (self)) 53 | 54 | /*****************************************************************************/ 55 | /* Print support */ 56 | 57 | gchar *_mbim_tlv_print (const MbimTlv *tlv, 58 | const gchar *line_prefix); 59 | 60 | /*****************************************************************************/ 61 | /* Parsing support */ 62 | 63 | MbimTlv *_mbim_tlv_new_from_raw (const guint8 *raw, 64 | guint32 raw_length, 65 | guint32 *bytes_read, 66 | GError **error); 67 | 68 | G_END_DECLS 69 | 70 | #endif /* _LIBMBIM_GLIB_MBIM_TLV_PRIVATE_H_ */ 71 | -------------------------------------------------------------------------------- /src/libmbim-glib/mbim-utils.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * libmbim-glib -- GLib/GIO based library to control MBIM devices 5 | * 6 | * Copyright (C) 2013 - 2019 Aleksander Morgado 7 | */ 8 | 9 | #include "mbim-utils.h" 10 | 11 | /** 12 | * SECTION:mbim-utils 13 | * @title: Common utilities 14 | * @short_description: Common utilities in the libmbim-glib library. 15 | * 16 | * This section exposes a set of common utilities that may be used to work 17 | * with the libmbim-glib library. 18 | */ 19 | 20 | static volatile gint __traces_enabled = FALSE; 21 | static volatile gint __hide_personal_info = FALSE; 22 | 23 | gboolean 24 | mbim_utils_get_traces_enabled (void) 25 | { 26 | return (gboolean) g_atomic_int_get (&__traces_enabled); 27 | } 28 | 29 | void 30 | mbim_utils_set_traces_enabled (gboolean enabled) 31 | { 32 | g_atomic_int_set (&__traces_enabled, enabled); 33 | } 34 | 35 | void 36 | mbim_utils_set_show_personal_info (gboolean hide_personal_info) 37 | { 38 | g_atomic_int_set (&__hide_personal_info, hide_personal_info); 39 | } 40 | 41 | gboolean 42 | mbim_utils_get_show_personal_info (void) 43 | { 44 | return (gboolean) g_atomic_int_get (&__hide_personal_info); 45 | } 46 | -------------------------------------------------------------------------------- /src/libmbim-glib/mbim-utils.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * libmbim-glib -- GLib/GIO based library to control MBIM devices 5 | * 6 | * Copyright (C) 2013 - 2014 Aleksander Morgado 7 | */ 8 | 9 | #ifndef _LIBMBIM_GLIB_MBIM_UTILS_H_ 10 | #define _LIBMBIM_GLIB_MBIM_UTILS_H_ 11 | 12 | #if !defined (__LIBMBIM_GLIB_H_INSIDE__) && !defined (LIBMBIM_GLIB_COMPILATION) 13 | #error "Only can be included directly." 14 | #endif 15 | 16 | #include 17 | 18 | G_BEGIN_DECLS 19 | 20 | /* Enabling/Disabling traces */ 21 | 22 | /** 23 | * mbim_utils_get_traces_enabled: 24 | * 25 | * Checks whether MBIM message traces are currently enabled. 26 | * 27 | * Returns: %TRUE if traces are enabled, %FALSE otherwise. 28 | * 29 | * Since: 1.0 30 | */ 31 | gboolean mbim_utils_get_traces_enabled (void); 32 | 33 | /** 34 | * mbim_utils_set_traces_enabled: 35 | * @enabled: %TRUE to enable traces, %FALSE to disable them. 36 | * 37 | * Sets whether MBIM message traces are enabled or disabled. 38 | * 39 | * Since: 1.0 40 | */ 41 | void mbim_utils_set_traces_enabled (gboolean enabled); 42 | 43 | /** 44 | * mbim_utils_set_show_personal_info: 45 | * @show_personal_info: %TRUE to show personal info in traces, %FALSE otherwise. 46 | * 47 | * Sets whether personal info is printed when traces are enabled. 48 | * 49 | * Since: 1.28 50 | */ 51 | void mbim_utils_set_show_personal_info (gboolean show_personal_info); 52 | 53 | /** 54 | * mbim_utils_get_show_personal_info: 55 | * 56 | * Checks whether personal info should be hidden when traces are enabled. 57 | * 58 | * Returns: %TRUE to show personal info in trace, %FALSE otherwise. 59 | * 60 | * Since: 1.28 61 | */ 62 | gboolean mbim_utils_get_show_personal_info (void); 63 | 64 | G_END_DECLS 65 | 66 | #endif /* _LIBMBIM_GLIB_MBIM_UTILS_H_ */ 67 | -------------------------------------------------------------------------------- /src/libmbim-glib/mbim-version.h.in: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ 3 | /* 4 | * Copyright (C) 2013 Lanedo GmbH 5 | * Copyright (C) 2013 - 2014 Aleksander Morgado 6 | */ 7 | 8 | #ifndef _MBIM_VERSION_H_ 9 | #define _MBIM_VERSION_H_ 10 | 11 | /** 12 | * SECTION:mbim-version 13 | * @short_description: Version information in the API. 14 | * 15 | * This section defines types that are used to identify the libmbim-glib version. 16 | **/ 17 | 18 | /** 19 | * MBIM_MAJOR_VERSION: 20 | * 21 | * Evaluates to the major version number of libmbim-glib which this source 22 | * is compiled against. 23 | * 24 | * Since: 1.2 25 | */ 26 | #define MBIM_MAJOR_VERSION (@MBIM_MAJOR_VERSION@) 27 | 28 | /** 29 | * MBIM_MINOR_VERSION: 30 | * 31 | * Evaluates to the minor version number of libmbim-glib which this source 32 | * is compiled against. 33 | * 34 | * Since: 1.2 35 | */ 36 | #define MBIM_MINOR_VERSION (@MBIM_MINOR_VERSION@) 37 | 38 | /** 39 | * MBIM_MICRO_VERSION: 40 | * 41 | * Evaluates to the micro version number of libmbim-glib which this source 42 | * compiled against. 43 | * 44 | * Since: 1.2 45 | */ 46 | #define MBIM_MICRO_VERSION (@MBIM_MICRO_VERSION@) 47 | 48 | /** 49 | * MBIM_CHECK_VERSION: 50 | * @major: major version (e.g. 1 for version 1.2.5) 51 | * @minor: minor version (e.g. 2 for version 1.2.5) 52 | * @micro: micro version (e.g. 5 for version 1.2.5) 53 | * 54 | * Checks the version of the library that is being compiled against. 55 | * 56 | * Returns: %TRUE if the version of the libmbim-glib header files 57 | * is the same as or newer than the passed-in version. 58 | * 59 | * Since: 1.2 60 | */ 61 | #define MBIM_CHECK_VERSION(major,minor,micro) \ 62 | (MBIM_MAJOR_VERSION > (major) || \ 63 | (MBIM_MAJOR_VERSION == (major) && MBIM_MINOR_VERSION > (minor)) || \ 64 | (MBIM_MAJOR_VERSION == (major) && MBIM_MINOR_VERSION == (minor) && MBIM_MICRO_VERSION >= (micro))) 65 | 66 | #endif /* _MBIM_VERSION_H_ */ 67 | -------------------------------------------------------------------------------- /src/libmbim-glib/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | libmbim_glib_inc = include_directories('.') 5 | 6 | mbim_errors_header = files('mbim-errors.h') 7 | 8 | mbim_enums_headers = files( 9 | 'mbim-cid.h', 10 | 'mbim-enums.h', 11 | 'mbim-message.h', 12 | 'mbim-uuid.h', 13 | 'mbim-tlv.h', 14 | ) 15 | 16 | subdir('generated') 17 | 18 | headers = mbim_errors_header + mbim_enums_headers + files( 19 | 'libmbim-glib.h', 20 | 'mbim-compat.h', 21 | 'mbim-device.h', 22 | 'mbim-proxy.h', 23 | 'mbim-utils.h', 24 | ) 25 | 26 | install_headers( 27 | headers, 28 | install_dir: mbim_glib_pkgincludedir, 29 | ) 30 | 31 | common_c_flags = [ 32 | '-DLIBMBIM_GLIB_COMPILATION', 33 | '-DG_LOG_DOMAIN="Mbim"', 34 | '-DLIBEXEC_PATH="@0@"'.format(mbim_prefix / mbim_libexecdir), 35 | ] 36 | 37 | sources = files( 38 | 'mbim-cid.c', 39 | 'mbim-compat.c', 40 | 'mbim-device.c', 41 | 'mbim-helpers.c', 42 | 'mbim-helpers-netlink.c', 43 | 'mbim-message.c', 44 | 'mbim-net-port-manager.c', 45 | 'mbim-net-port-manager-wdm.c', 46 | 'mbim-net-port-manager-wwan.c', 47 | 'mbim-proxy.c', 48 | 'mbim-proxy-helpers.c', 49 | 'mbim-utils.c', 50 | 'mbim-uuid.c', 51 | 'mbim-tlv.c', 52 | ) 53 | 54 | deps = [ 55 | generated_dep, 56 | libmbim_common_dep, 57 | ] 58 | 59 | libmbim_glib_core = static_library( 60 | 'mbim-glib-core', 61 | sources: sources, 62 | include_directories: top_inc, 63 | dependencies: deps + [gio_unix_dep], 64 | c_args: common_c_flags, 65 | link_whole: libmbim_glib_generated, 66 | ) 67 | 68 | libmbim_glib_core_dep = declare_dependency( 69 | include_directories: libmbim_glib_inc, 70 | dependencies: deps, 71 | link_with: libmbim_glib_core, 72 | ) 73 | 74 | libname = 'mbim-glib' 75 | 76 | version_header = configure_file( 77 | input: 'mbim-version.h.in', 78 | output: '@BASENAME@', 79 | configuration: version_conf, 80 | install_dir: mbim_glib_pkgincludedir, 81 | ) 82 | 83 | symbol_map = meson.current_source_dir() / 'symbol.map' 84 | ldflags = cc.get_supported_link_arguments('-Wl,--version-script,@0@'.format(symbol_map)) 85 | 86 | libmbim_glib = library( 87 | libname, 88 | version: mbim_glib_version, 89 | sources: version_header, 90 | include_directories: top_inc, 91 | dependencies: generated_dep, 92 | link_args: ldflags, 93 | link_depends: symbol_map, 94 | link_whole: libmbim_glib_core, 95 | install: true, 96 | ) 97 | 98 | libmbim_glib_dep = declare_dependency( 99 | sources: [gen_headers, version_header], 100 | include_directories: [libmbim_glib_inc, generated_inc], 101 | dependencies: glib_deps, 102 | link_with: libmbim_glib, 103 | ) 104 | 105 | pkg.generate( 106 | libraries: libmbim_glib, 107 | version: mbim_version, 108 | name: libname, 109 | description: 'Library to communicate with MBIM-powered modems', 110 | subdirs: mbim_glib_include_subdir, 111 | # FIXME: produced by the inhability of meson to use internal dependencies 112 | requires: ['glib-2.0', 'gobject-2.0', 'gio-2.0'], 113 | variables: 'exec_prefix=${prefix}', 114 | ) 115 | 116 | # Introspection 117 | if enable_gir and get_option('default_library') != 'static' 118 | incs = [ 119 | 'Gio-2.0', 120 | 'GLib-2.0', 121 | 'GObject-2.0', 122 | ] 123 | 124 | ns = 'Mbim' 125 | 126 | libmbim_glib_gir = gnome.generate_gir( 127 | libmbim_glib, 128 | sources: headers + [version_header] + gen_sources + gen_headers, 129 | includes: incs, 130 | dependencies: libmbim_glib_dep, 131 | namespace: ns, 132 | nsversion: mbim_gir_version, 133 | identifier_prefix: ns, 134 | symbol_prefix: ns.to_lower() + '_', 135 | extra_args: common_c_flags + ['--identifier-prefix=' + ns.to_upper()], 136 | header: 'libmbim-glib.h', 137 | export_packages: libname, 138 | install: true, 139 | ) 140 | endif 141 | 142 | if enable_mbim_username 143 | configure_file( 144 | input: '76-mbim-device-ownership.rules.in', 145 | output: '@BASENAME@', 146 | configuration: {'MBIM_USERNAME': mbim_username}, 147 | install_dir: udev_udevdir / 'rules.d', 148 | ) 149 | endif 150 | 151 | 152 | subdir('test') 153 | -------------------------------------------------------------------------------- /src/libmbim-glib/symbol.map: -------------------------------------------------------------------------------- 1 | { 2 | global: 3 | mbim_*; 4 | local: 5 | *; 6 | }; 7 | -------------------------------------------------------------------------------- /src/libmbim-glib/test/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | test_units = [ 5 | 'uuid', 6 | 'cid', 7 | 'message', 8 | 'fragment', 9 | 'message-fuzzer-samples', 10 | 'message-parser', 11 | 'message-builder', 12 | 'proxy-helpers', 13 | ] 14 | 15 | test_env = { 16 | 'G_DEBUG': 'gc-friendly', 17 | 'MALLOC_CHECK_': '2', 18 | 'G_TEST_SRCDIR': meson.current_source_dir(), 19 | 'G_TEST_BUILDDIR': meson.current_build_dir(), 20 | } 21 | 22 | foreach test_unit: test_units 23 | test_name = 'test-' + test_unit 24 | 25 | exe = executable( 26 | test_name, 27 | sources: test_name + '.c', 28 | include_directories: top_inc, 29 | dependencies: libmbim_glib_core_dep, 30 | c_args: '-DLIBMBIM_GLIB_COMPILATION', 31 | ) 32 | 33 | test( 34 | test_unit, 35 | exe, 36 | env: test_env, 37 | ) 38 | endforeach 39 | 40 | if get_option('fuzzer') 41 | fuzzer_name = 'test-message-fuzzer' 42 | exe = executable( 43 | fuzzer_name, 44 | sources: fuzzer_name + '.c', 45 | include_directories: top_inc, 46 | dependencies: libmbim_glib_core_dep, 47 | c_args: '-DLIBMBIM_GLIB_COMPILATION', 48 | link_args : '-fsanitize=fuzzer', 49 | ) 50 | endif 51 | -------------------------------------------------------------------------------- /src/libmbim-glib/test/test-cid.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * Copyright (C) 2013 - 2014 Aleksander Morgado 5 | */ 6 | 7 | #include 8 | 9 | #include "mbim-cid.h" 10 | 11 | static void 12 | test_common (MbimService service, 13 | guint cid, 14 | gboolean can_set, 15 | gboolean can_query, 16 | gboolean can_notify) 17 | { 18 | g_assert (mbim_cid_can_set (service, cid) == can_set); 19 | g_assert (mbim_cid_can_query (service, cid) == can_query); 20 | g_assert (mbim_cid_can_notify (service, cid) == can_notify); 21 | } 22 | 23 | static void 24 | test_cid_basic_connect (void) 25 | { 26 | test_common (MBIM_SERVICE_BASIC_CONNECT, 27 | MBIM_CID_BASIC_CONNECT_DEVICE_CAPS, 28 | FALSE, TRUE, FALSE); 29 | 30 | test_common (MBIM_SERVICE_BASIC_CONNECT, 31 | MBIM_CID_BASIC_CONNECT_MULTICARRIER_PROVIDERS, 32 | TRUE, TRUE, TRUE); 33 | } 34 | 35 | static void 36 | test_cid_sms (void) 37 | { 38 | test_common (MBIM_SERVICE_SMS, 39 | MBIM_CID_SMS_CONFIGURATION, 40 | TRUE, TRUE, TRUE); 41 | 42 | test_common (MBIM_SERVICE_SMS, 43 | MBIM_CID_SMS_MESSAGE_STORE_STATUS, 44 | FALSE, TRUE, TRUE); 45 | } 46 | 47 | static void 48 | test_cid_ussd (void) 49 | { 50 | test_common (MBIM_SERVICE_USSD, 51 | MBIM_CID_USSD, 52 | TRUE, FALSE, TRUE); 53 | } 54 | 55 | static void 56 | test_cid_phonebook (void) 57 | { 58 | test_common (MBIM_SERVICE_PHONEBOOK, 59 | MBIM_CID_PHONEBOOK_CONFIGURATION, 60 | FALSE, TRUE, TRUE); 61 | 62 | test_common (MBIM_SERVICE_PHONEBOOK, 63 | MBIM_CID_PHONEBOOK_WRITE, 64 | TRUE, FALSE, FALSE); 65 | } 66 | 67 | static void 68 | test_cid_stk (void) 69 | { 70 | test_common (MBIM_SERVICE_STK, 71 | MBIM_CID_STK_PAC, 72 | TRUE, TRUE, TRUE); 73 | 74 | test_common (MBIM_SERVICE_STK, 75 | MBIM_CID_STK_ENVELOPE, 76 | TRUE, TRUE, FALSE); 77 | } 78 | 79 | static void 80 | test_cid_auth (void) 81 | { 82 | test_common (MBIM_SERVICE_AUTH, 83 | MBIM_CID_AUTH_AKA, 84 | FALSE, TRUE, FALSE); 85 | 86 | test_common (MBIM_SERVICE_AUTH, 87 | MBIM_CID_AUTH_SIM, 88 | FALSE, TRUE, FALSE); 89 | } 90 | 91 | static void 92 | test_cid_dss (void) 93 | { 94 | test_common (MBIM_SERVICE_DSS, 95 | MBIM_CID_DSS_CONNECT, 96 | TRUE, FALSE, FALSE); 97 | } 98 | 99 | static void 100 | test_cid_ms_firmware_id (void) 101 | { 102 | test_common (MBIM_SERVICE_MS_FIRMWARE_ID, 103 | MBIM_CID_MS_FIRMWARE_ID_GET, 104 | FALSE, TRUE, FALSE); 105 | } 106 | 107 | static void 108 | test_cid_ms_host_shutdown (void) 109 | { 110 | test_common (MBIM_SERVICE_MS_HOST_SHUTDOWN, 111 | MBIM_CID_MS_HOST_SHUTDOWN_NOTIFY, 112 | TRUE, FALSE, FALSE); 113 | } 114 | 115 | static void 116 | test_cid_ms_sar (void) 117 | { 118 | test_common (MBIM_SERVICE_MS_SAR, 119 | MBIM_CID_MS_SAR_CONFIG, 120 | TRUE, TRUE, TRUE); 121 | } 122 | 123 | int main (int argc, char **argv) 124 | { 125 | g_test_init (&argc, &argv, NULL); 126 | 127 | g_test_add_func ("/libmbim-glib/cid/basic-connect", test_cid_basic_connect); 128 | g_test_add_func ("/libmbim-glib/cid/sms", test_cid_sms); 129 | g_test_add_func ("/libmbim-glib/cid/ussd", test_cid_ussd); 130 | g_test_add_func ("/libmbim-glib/cid/phonebook", test_cid_phonebook); 131 | g_test_add_func ("/libmbim-glib/cid/stk", test_cid_stk); 132 | g_test_add_func ("/libmbim-glib/cid/auth", test_cid_auth); 133 | g_test_add_func ("/libmbim-glib/cid/dss", test_cid_dss); 134 | g_test_add_func ("/libmbim-glib/cid/ms-firmware-id", test_cid_ms_firmware_id); 135 | g_test_add_func ("/libmbim-glib/cid/ms-host-shutdown", test_cid_ms_host_shutdown); 136 | g_test_add_func ("/libmbim-glib/cid/ms-sar", test_cid_ms_sar); 137 | 138 | return g_test_run (); 139 | } 140 | -------------------------------------------------------------------------------- /src/libmbim-glib/test/test-message-fuzzer-samples.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * Copyright (C) 2023 Google, Inc. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /* Include the whole fuzzer test file */ 13 | int LLVMFuzzerTestOneInput (const uint8_t *data, 14 | size_t size); 15 | #include "test-message-fuzzer.c" 16 | 17 | static void 18 | test_fuzzer_sample_basic (void) 19 | { 20 | const guint8 data[] = { 0x3 }; 21 | 22 | g_assert_cmpuint (LLVMFuzzerTestOneInput (data, G_N_ELEMENTS (data)), ==, 0); 23 | } 24 | 25 | static void 26 | test_fuzzer_sample_invalid_array_size (void) 27 | { 28 | const guint8 data[] = { 29 | 0x3,0x0,0x0,0x80,0x46,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1, 30 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x68,0x22,0x3d,0x4,0x9f, 31 | 0x6c,0x4e,0xf,0x82,0x2d,0x28,0x44,0x1f,0xb7,0x23,0x40, 32 | 0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5,0x0,0x0,0x0,0x0, 33 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2e,0xb7,0x23, 34 | 0x40,0x59,0x67,0xbd,0xcc,0x7f,0xd2,0x49,0xa2,0x9f,0x5c, 35 | 0xb2,0xe7,0xe,0x52,0x7d,0xb3,0x1,0x0,0x0,0x0,0x23,0x40, 36 | 0x1,0x0,0x0,0x0,0x0,0x3,0x0,0x0,0x9 }; 37 | 38 | g_assert_cmpuint (LLVMFuzzerTestOneInput (data, G_N_ELEMENTS (data)), ==, 0); 39 | } 40 | 41 | static void 42 | test_fuzzer_sample_invalid_offset_unbound_bytearray (void) 43 | { 44 | const guint8 data[] = { 45 | 0x3,0x0,0x0,0x80,0x31,0x0,0x0,0x0,0x0,0x4c,0x0,0x0,0x1, 46 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc2,0xf6,0x58,0x8e,0xf0,0x37, 47 | 0x4b,0xc9,0x86,0x65,0xf4,0xd4,0x4b,0xd0,0x93,0x67,0x5,0x0, 48 | 0x0,0x0,0x4c,0x0,0x5d,0x0,0x1,0x0,0x0,0x0,0x0,0x4,0x0,0x0, 49 | 0x80,0x0,0x0,0x0,0xa0,0x0,0x0,0x1,0x0,0x80,0x32 }; 50 | 51 | g_assert_cmpuint (LLVMFuzzerTestOneInput (data, G_N_ELEMENTS (data)), ==, 0); 52 | } 53 | 54 | static void 55 | test_fuzzer_sample_ms_struct_array_with_string (void) 56 | { 57 | const guint8 data[] = { 58 | 0x3,0x0,0x0,0x80,0x54,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0, 59 | 0x0,0x0,0x0,0x0,0x0,0x0,0x3d,0x1,0xdc,0xc5,0xfe,0xf5,0x4d, 60 | 0x5,0xd,0x3a,0xbe,0xf7,0x5,0x8e,0x9a,0xaf,0xb,0x0,0x0,0x0, 61 | 0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x40,0x0,0x7a,0x1d,0x0, 62 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 63 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x12,0x0, 64 | 0x0,0x0,0x0,0x0,0x0,0x7a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 65 | 0x3b,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0, 66 | 0x0,0x0,0x0,0x0,0x0,0xa2,0x89,0xcc,0x33,0xbc,0xbb,0x8b,0x4f, 67 | 0xb6,0xb0,0x13,0x3e,0xc2,0xaa,0xe6,0xdf,0x1,0x0,0x0,0x0,0x0, 68 | 0x0,0x2,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa4,0xa4,0x3, 69 | 0x0,0x0,0x0,0x24,0x0,0x0,0xfe,0xf5,0x4d,0x5,0xd,0x3a,0xbe, 70 | 0xf7,0x5,0x8e,0x9a,0xaf,0xb,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1, 71 | 0x0,0x0,0x0,0x0,0x40,0x0,0x7a,0x1d,0x0,0x0,0x0,0x0,0x0,0x0, 72 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 73 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x12,0x0,0x0,0x0,0x0,0x0,0x0, 74 | 0x0,0x0,0x15,0x0,0x0,0x0,0x80,0xad,0xa4,0x9b,0x9b,0x9b,0xbd, 75 | 0xbd 76 | }; 77 | 78 | g_assert_cmpuint (LLVMFuzzerTestOneInput (data, G_N_ELEMENTS (data)), ==, 0); 79 | } 80 | 81 | static void 82 | test_fuzzer_sample_ref_struct_array_with_unsized_bytearrays (void) 83 | { 84 | const guint8 data[] = { 85 | 0x3,0x0,0x0,0x80,0x33,0x0,0x0,0x0,0x0,0x0,0x55,0x8,0x1,0x0,0x0, 86 | 0x0,0x0,0x0,0x0,0x0,0xc2,0xf6,0x58,0x8e,0xf0,0x37,0x4b,0xc9,0x86, 87 | 0x65,0xf4,0xd4,0x4b,0xd0,0x93,0x67,0x5,0x0,0x0,0x0,0x32,0x0,0x0, 88 | 0x0,0x1,0x0,0x0,0x0,0x0,0x1,0x0,0xff,0xff,0xff,0xff,0xff,0xff, 89 | 0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 90 | 0x0,0xb0,0x13,0x12,0x0,0xca,0xca,0xca,0x0,0x0,0xe8 91 | }; 92 | 93 | g_assert_cmpuint (LLVMFuzzerTestOneInput (data, G_N_ELEMENTS (data)), ==, 0); 94 | } 95 | 96 | int main (int argc, char **argv) 97 | { 98 | g_test_init (&argc, &argv, NULL); 99 | 100 | #define PREFIX "/libmbim-glib/message/fuzzer-samples/" 101 | g_test_add_func (PREFIX "basic", test_fuzzer_sample_basic); 102 | g_test_add_func (PREFIX "invalid-arraysize", test_fuzzer_sample_invalid_array_size); 103 | g_test_add_func (PREFIX "invalid-offset-unbound-bytearray", test_fuzzer_sample_invalid_offset_unbound_bytearray); 104 | g_test_add_func (PREFIX "ms-struct-array-with-string", test_fuzzer_sample_ms_struct_array_with_string); 105 | g_test_add_func (PREFIX "ref-struct-array-with-unsized-bytearrays", test_fuzzer_sample_ref_struct_array_with_unsized_bytearrays); 106 | #undef PREFIX 107 | return g_test_run (); 108 | } 109 | -------------------------------------------------------------------------------- /src/libmbim-glib/test/test-message-fuzzer.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * Copyright (C) 2022 Google, Inc. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "mbim-message.h" 13 | 14 | int 15 | LLVMFuzzerTestOneInput (const uint8_t *data, 16 | size_t size) 17 | { 18 | g_autoptr(MbimMessage) message = NULL; 19 | g_autoptr(GError) error = NULL; 20 | guint mbimex_version_major; 21 | 22 | if (!size) 23 | return 0; 24 | 25 | message = mbim_message_new (data, size); 26 | if (!mbim_message_validate (message, &error)) { 27 | g_printerr ("error: %s\n", error->message); 28 | return 0; 29 | } 30 | 31 | /* We support printing as MBIMEx 1, 2 and 3 */ 32 | for (mbimex_version_major = 1; mbimex_version_major <= 3; mbimex_version_major++) { 33 | g_autofree gchar *printable = NULL; 34 | g_autoptr(GError) inner_error = NULL; 35 | 36 | printable = mbim_message_get_printable_full (message, mbimex_version_major, 0, "---- ", FALSE, &inner_error); 37 | if (!printable) 38 | g_printerr ("error: %s\n", inner_error->message); 39 | else 40 | g_print ("%s\n", printable); 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /src/mbim-proxy/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | name = 'mbim-proxy' 5 | 6 | executable( 7 | name, 8 | sources: name + '.c', 9 | include_directories: top_inc, 10 | dependencies: libmbim_glib_dep, 11 | install: true, 12 | install_dir: mbim_libexecdir, 13 | ) 14 | -------------------------------------------------------------------------------- /src/mbimcli/mbimcli: -------------------------------------------------------------------------------- 1 | # mbimcli(1) completion -*- shell-script -*- 2 | 3 | # SPDX-License-Identifier: GPL-2.0-or-later 4 | # 5 | # Copyright (C) 2015 Aleksander Morgado 6 | 7 | _mbimcli() 8 | { 9 | local cur prev words cword split 10 | _init_completion -s || return 11 | 12 | case $prev in 13 | '-d'|'--device') 14 | _filedir 15 | return 0 16 | ;; 17 | '--no-open') 18 | COMPREPLY=( $(compgen -W "[Transaction-ID]" -- $cur) ) 19 | return 0 20 | ;; 21 | '--set-radio-state') 22 | COMPREPLY=( $(compgen -W "[(on|off)]" -- $cur) ) 23 | return 0 24 | ;; 25 | '--enter-pin') 26 | COMPREPLY=( $(compgen -W "[current-PIN]" -- $cur) ) 27 | return 0 28 | ;; 29 | '--change-pin') 30 | COMPREPLY=( $(compgen -W "[(current-PIN),(new-PIN)]" -- $cur) ) 31 | return 0 32 | ;; 33 | '--enable-pin') 34 | COMPREPLY=( $(compgen -W "[current-PIN]" -- $cur) ) 35 | return 0 36 | ;; 37 | '--disable-pin') 38 | COMPREPLY=( $(compgen -W "[current-PIN]" -- $cur) ) 39 | return 0 40 | ;; 41 | '--enter-puk') 42 | COMPREPLY=( $(compgen -W "[(PUK),(new-PIN)]" -- $cur) ) 43 | return 0 44 | ;; 45 | '--connect') 46 | COMPREPLY=( $(compgen -W "[(APN),(PAP|CHAP|MSCHAPV2),(Username),(Password)]" -- $cur) ) 47 | return 0 48 | ;; 49 | '--phonebook-read') 50 | COMPREPLY=( $(compgen -W "[(Phonebook-index)]" -- $cur) ) 51 | return 0 52 | ;; 53 | '--phonebook-write') 54 | COMPREPLY=( $(compgen -W "[(Name),(Number)[,(Index)]]" -- $cur) ) 55 | return 0 56 | ;; 57 | '--phonebook-delete') 58 | COMPREPLY=( $(compgen -W "[(Phonebook-index)]" -- $cur) ) 59 | return 0 60 | ;; 61 | '--dss-connect') 62 | COMPREPLY=( $(compgen -W "[(UUID),(Session-ID)]" -- $cur) ) 63 | return 0 64 | ;; 65 | '--dss-disconnect') 66 | COMPREPLY=( $(compgen -W "[(UUID),(Session-ID)]" -- $cur) ) 67 | return 0 68 | ;; 69 | '-V'|'--version') 70 | return 0 71 | ;; 72 | '-h'|'--help'|'--help-all'|'--help-basic-connect'|'--help-phonebook'|'--help-dss'|'--help-ms-firmware-id'|'--help-ms-host-shutdown'|'--help-ms-sar') 73 | return 0 74 | ;; 75 | esac 76 | 77 | $split && return 0 78 | 79 | if [[ $cur == -* ]]; then 80 | COMPREPLY=( $( compgen -W '$( _parse_help "$1" --help-all )' -- "$cur" ) ) 81 | [[ $COMPREPLY == *= ]] && compopt -o nospace 82 | return 0 83 | fi 84 | } && 85 | complete -F _mbimcli mbimcli 86 | 87 | # ex: ts=4 sw=4 et filetype=sh 88 | -------------------------------------------------------------------------------- /src/mbimcli/mbimcli-compal.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * mbimcli -- Command line interface to control MBIM devices 5 | * 6 | * Copyright (C) 2023 chenhaotian 7 | */ 8 | 9 | #include "config.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #include "mbimcli.h" 22 | #include "mbimcli-helpers.h" 23 | 24 | /* Context */ 25 | typedef struct { 26 | MbimDevice *device; 27 | GCancellable *cancellable; 28 | } Context; 29 | static Context *ctx; 30 | 31 | /* Options */ 32 | static gchar *query_at_command_str; 33 | 34 | static GOptionEntry entries[] = { 35 | { "compal-query-at-command", 0, 0, G_OPTION_ARG_STRING, &query_at_command_str, 36 | "send AT command to modem, and receive AT response", 37 | "\"\"" 38 | }, 39 | { NULL, 0, 0, 0, NULL, NULL, NULL } 40 | }; 41 | 42 | GOptionGroup * 43 | mbimcli_compal_get_option_group (void) 44 | { 45 | GOptionGroup *group; 46 | 47 | group = g_option_group_new ("compal", 48 | "Compal options:", 49 | "Show Compal Service options", 50 | NULL, 51 | NULL); 52 | g_option_group_add_entries (group, entries); 53 | return group; 54 | } 55 | 56 | gboolean 57 | mbimcli_compal_options_enabled (void) 58 | { 59 | static guint n_actions = 0; 60 | static gboolean checked = FALSE; 61 | 62 | if (checked) 63 | return !!n_actions; 64 | 65 | n_actions = !!query_at_command_str; 66 | 67 | if (n_actions > 1) { 68 | g_printerr ("error: too many compal actions requested\n"); 69 | exit (EXIT_FAILURE); 70 | } 71 | 72 | checked = TRUE; 73 | return !!n_actions; 74 | } 75 | 76 | static void 77 | context_free (Context *context) 78 | { 79 | if (!context) 80 | return; 81 | 82 | if (context->cancellable) 83 | g_object_unref (context->cancellable); 84 | if (context->device) 85 | g_object_unref (context->device); 86 | g_slice_free (Context, context); 87 | } 88 | 89 | static void 90 | shutdown (gboolean operation_status) 91 | { 92 | /* Cleanup context and finish async operation */ 93 | context_free (ctx); 94 | mbimcli_async_operation_done (operation_status); 95 | } 96 | 97 | static void 98 | compal_at_command_ready (MbimDevice *device, 99 | GAsyncResult *res) 100 | { 101 | g_autoptr(GError) error = NULL; 102 | guint32 ret_size = 0; 103 | const guint8 *ret_str = NULL; 104 | g_autoptr(MbimMessage) response = NULL; 105 | 106 | response = mbim_device_command_finish (device, res, &error); 107 | 108 | if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) { 109 | g_printerr ("error: operation failed: %s\n", error->message); 110 | shutdown (FALSE); 111 | return; 112 | } 113 | 114 | if (!mbim_message_compal_at_command_response_parse ( 115 | response, 116 | &ret_size, 117 | &ret_str, 118 | &error)) { 119 | g_printerr ("error: couldn't parse response message: %s\n", error->message); 120 | shutdown (FALSE); 121 | return; 122 | } 123 | 124 | g_print ("%.*s\n", ret_size, ret_str); 125 | 126 | shutdown (TRUE); 127 | } 128 | 129 | void 130 | mbimcli_compal_run (MbimDevice *device, 131 | GCancellable *cancellable) 132 | { 133 | g_autoptr(MbimMessage) request = NULL; 134 | g_autofree gchar *req_str = NULL; 135 | guint32 req_size = 0; 136 | 137 | /* Initialize context */ 138 | ctx = g_slice_new (Context); 139 | ctx->device = g_object_ref (device); 140 | ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; 141 | 142 | /* Request to send AT command */ 143 | if (query_at_command_str) { 144 | req_str = g_strdup_printf ("%s\r\n", query_at_command_str); 145 | req_size = strlen (req_str); 146 | 147 | request = mbim_message_compal_at_command_query_new (req_size, (const guint8 *)req_str, NULL); 148 | mbim_device_command (ctx->device, 149 | request, 150 | 10, 151 | ctx->cancellable, 152 | (GAsyncReadyCallback)compal_at_command_ready, 153 | NULL); 154 | return; 155 | } 156 | 157 | g_warn_if_reached (); 158 | } 159 | -------------------------------------------------------------------------------- /src/mbimcli/mbimcli-fibocom.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * mbimcli -- Command line interface to control MBIM devices 5 | * 6 | * Copyright (C) 2023 chenhaotian 7 | */ 8 | 9 | #include "config.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #include "mbimcli.h" 22 | #include "mbimcli-helpers.h" 23 | 24 | /* Context */ 25 | typedef struct { 26 | MbimDevice *device; 27 | GCancellable *cancellable; 28 | } Context; 29 | static Context *ctx; 30 | 31 | /* Options */ 32 | static gchar *set_at_command_str; 33 | 34 | static GOptionEntry entries[] = { 35 | { "fibocom-set-at-command", 0, 0, G_OPTION_ARG_STRING, &set_at_command_str, 36 | "send AT command to modem, and receive AT response", 37 | "\"\"" 38 | }, 39 | { NULL, 0, 0, 0, NULL, NULL, NULL } 40 | }; 41 | 42 | GOptionGroup * 43 | mbimcli_fibocom_get_option_group (void) 44 | { 45 | GOptionGroup *group; 46 | 47 | group = g_option_group_new ("fibocom", 48 | "FIbocom options:", 49 | "Show Fibocom Service options", 50 | NULL, 51 | NULL); 52 | g_option_group_add_entries (group, entries); 53 | return group; 54 | } 55 | 56 | gboolean 57 | mbimcli_fibocom_options_enabled (void) 58 | { 59 | static guint n_actions = 0; 60 | static gboolean checked = FALSE; 61 | 62 | if (checked) 63 | return !!n_actions; 64 | 65 | n_actions = !!set_at_command_str; 66 | 67 | if (n_actions > 1) { 68 | g_printerr ("error: too many fibocom actions requested\n"); 69 | exit (EXIT_FAILURE); 70 | } 71 | 72 | checked = TRUE; 73 | return !!n_actions; 74 | } 75 | 76 | static void 77 | context_free (Context *context) 78 | { 79 | if (!context) 80 | return; 81 | 82 | if (context->cancellable) 83 | g_object_unref (context->cancellable); 84 | if (context->device) 85 | g_object_unref (context->device); 86 | g_slice_free (Context, context); 87 | } 88 | 89 | static void 90 | shutdown (gboolean operation_status) 91 | { 92 | /* Cleanup context and finish async operation */ 93 | context_free (ctx); 94 | mbimcli_async_operation_done (operation_status); 95 | } 96 | 97 | static void 98 | fibocom_ready (MbimDevice *device, 99 | GAsyncResult *res) 100 | { 101 | g_autoptr(GError) error = NULL; 102 | guint32 ret_size = 0; 103 | const guint8 *ret_str = NULL; 104 | g_autoptr(MbimMessage) response = NULL; 105 | 106 | response = mbim_device_command_finish (device, res, &error); 107 | 108 | if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) { 109 | g_printerr ("error: operation failed: %s\n", error->message); 110 | shutdown (FALSE); 111 | return; 112 | } 113 | 114 | if (!mbim_message_fibocom_at_command_response_parse ( 115 | response, 116 | &ret_size, 117 | &ret_str, 118 | &error)) { 119 | g_printerr ("error: couldn't parse response message: %s\n", error->message); 120 | shutdown (FALSE); 121 | return; 122 | } 123 | 124 | g_print ("%.*s\n", ret_size, ret_str); 125 | 126 | shutdown (TRUE); 127 | } 128 | 129 | void 130 | mbimcli_fibocom_run (MbimDevice *device, 131 | GCancellable *cancellable) 132 | { 133 | g_autoptr(MbimMessage) request = NULL; 134 | g_autofree gchar *req_str = NULL; 135 | guint32 req_size = 0; 136 | 137 | /* Initialize context */ 138 | ctx = g_slice_new (Context); 139 | ctx->device = g_object_ref (device); 140 | ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; 141 | 142 | /* Request to send AT command */ 143 | if (set_at_command_str) { 144 | req_str = g_strdup_printf ("%s\r\n", set_at_command_str); 145 | req_size = strlen (req_str); 146 | 147 | request = mbim_message_fibocom_at_command_set_new (req_size, (const guint8 *)req_str, NULL); 148 | mbim_device_command (ctx->device, 149 | request, 150 | 10, 151 | ctx->cancellable, 152 | (GAsyncReadyCallback)fibocom_ready, 153 | NULL); 154 | return; 155 | } 156 | 157 | g_warn_if_reached (); 158 | } 159 | -------------------------------------------------------------------------------- /src/mbimcli/mbimcli-helpers-quectel.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * mbimcli -- Command line interface to control MBIM devices 5 | * 6 | * Copyright (C) 2025 Dan Williams 7 | */ 8 | 9 | #include "config.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #include "mbimcli-helpers.h" 22 | #include "mbimcli-helpers-quectel.h" 23 | 24 | gboolean 25 | mbimcli_helpers_quectel_set_command_input_parse (const gchar *str, 26 | gchar **command_str, 27 | MbimQuectelCommandType *command_type) 28 | { 29 | g_auto(GStrv) split = NULL; 30 | guint num_parts = 0; 31 | g_autofree gchar *new_command = NULL; 32 | MbimQuectelCommandType new_command_type = *command_type; 33 | 34 | g_assert (command_str != NULL); 35 | 36 | /* Format of the string is: 37 | * "[\"Command\"]" 38 | * or: 39 | * "[(Command type),(\"Command\")]" 40 | */ 41 | split = g_strsplit (str, ",", -1); 42 | num_parts = g_strv_length (split); 43 | 44 | if (num_parts == 0 || !split[0]) { 45 | g_printerr ("error: The input string is empty, please re-enter.\n"); 46 | return FALSE; 47 | } 48 | 49 | /* The at command may have multiple commas, like:at+qcfg="usbcfg",0x2C7C,0x6008,0x00FF , 50 | * so we need to take the first split to see if it is the command type. 51 | * If it is, then combine the remaining splits into a string. 52 | * If not, combine the splits into a string. */ 53 | 54 | if (num_parts > 1) { 55 | g_autofree gchar *command_type_str = g_ascii_strdown (split[0], -1); 56 | 57 | if (mbimcli_read_quectel_command_type_from_string (command_type_str, &new_command_type, NULL)) { 58 | /* Valid Quectel command-type found */ 59 | new_command = g_strjoinv (",", split + 1); 60 | } else { 61 | /* No valid Quectel command-type found; assume plain AT command */ 62 | new_command = g_strdup (str); 63 | } 64 | } else { 65 | new_command = g_strdup (str); 66 | } 67 | 68 | if (!g_str_has_prefix (new_command, "AT") && !g_str_has_prefix (new_command, "at")) { 69 | g_printerr ("error: Wrong AT command '%s', command must start with \"AT\".\n", new_command); 70 | return FALSE; 71 | } 72 | 73 | *command_str = g_strdup (new_command); 74 | *command_type = new_command_type; 75 | return TRUE; 76 | } 77 | -------------------------------------------------------------------------------- /src/mbimcli/mbimcli-helpers-quectel.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * mbimcli -- Command line interface to control MBIM devices 5 | * 6 | * Copyright (C) 2025 Dan Williams 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | #ifndef __MBIMCLI_HELPERS_QUECTEL_H__ 14 | #define __MBIMCLI_HELPERS_QUECTEL_H__ 15 | 16 | gboolean mbimcli_helpers_quectel_set_command_input_parse (const gchar *str, 17 | gchar **command_str, 18 | MbimQuectelCommandType *command_type); 19 | 20 | #endif /* __MBIMCLI_HELPERS_QUECTEL_H__ */ 21 | -------------------------------------------------------------------------------- /src/mbimcli/mbimcli-helpers.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * mbimcli -- Command line interface to control QMI devices 5 | * 6 | * Copyright (C) 2014 Aleksander Morgado 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | #ifndef __MBIMCLI_HELPERS_H__ 14 | #define __MBIMCLI_HELPERS_H__ 15 | 16 | gboolean mbimcli_read_uint_from_string (const gchar *str, 17 | guint *out); 18 | gboolean mbimcli_read_uint_from_bcd_string (const gchar *str, 19 | guint *out); 20 | gboolean mbimcli_read_uint8_from_bcd_string (const gchar *str, 21 | guint8 *out); 22 | 23 | gboolean mbimcli_read_boolean_from_string (const gchar *value, 24 | gboolean *out); 25 | 26 | guint8 *mbimcli_read_buffer_from_string (const gchar *hex, 27 | gssize len, 28 | gsize *out_len, 29 | GError **error); 30 | 31 | gboolean mbimcli_print_ip_config (MbimDevice *device, 32 | MbimMessage *response, 33 | GError **error); 34 | 35 | typedef gboolean (*MbimParseKeyValueForeachFn) (const gchar *key, 36 | const gchar *value, 37 | GError **error, 38 | gpointer user_data); 39 | 40 | gboolean mbimcli_parse_key_value_string (const gchar *str, 41 | GError **error, 42 | MbimParseKeyValueForeachFn callback, 43 | gpointer user_data); 44 | 45 | gboolean mbimcli_parse_sar_config_state_array (const gchar *str, 46 | GPtrArray **out, 47 | GError **error); 48 | 49 | /* Common helpers to read enums from strings */ 50 | 51 | #define MBIMCLI_ENUM_LIST \ 52 | MBIMCLI_ENUM_LIST_ITEM (MbimPinType, pin_type, "pin type") \ 53 | MBIMCLI_ENUM_LIST_ITEM (MbimContextType, context_type, "context type") \ 54 | MBIMCLI_ENUM_LIST_ITEM (MbimContextIpType, context_ip_type, "context ip type") \ 55 | MBIMCLI_ENUM_LIST_ITEM (MbimContextState, context_state, "context state") \ 56 | MBIMCLI_ENUM_LIST_ITEM (MbimContextRoamingControl, context_roaming_control, "context roaming control") \ 57 | MBIMCLI_ENUM_LIST_ITEM (MbimContextMediaType, context_media_type, "context media type") \ 58 | MBIMCLI_ENUM_LIST_ITEM (MbimContextSource, context_source, "context source") \ 59 | MBIMCLI_ENUM_LIST_ITEM (MbimContextOperation, context_operation, "context operation") \ 60 | MBIMCLI_ENUM_LIST_ITEM (MbimAuthProtocol, auth_protocol, "auth protocol") \ 61 | MBIMCLI_ENUM_LIST_ITEM (MbimCompression, compression, "compression") \ 62 | MBIMCLI_ENUM_LIST_ITEM (MbimSarControlMode, sar_control_mode, "sar control mode") \ 63 | MBIMCLI_ENUM_LIST_ITEM (MbimSarBackoffState, sar_backoff_state, "sar backoff state") \ 64 | MBIMCLI_ENUM_LIST_ITEM (MbimMicoMode, mico_mode, "mico mode") \ 65 | MBIMCLI_ENUM_LIST_ITEM (MbimDrxCycle, drx_cycle, "drx cycle") \ 66 | MBIMCLI_ENUM_LIST_ITEM (MbimLadnInfo, ladn_info, "ladn info") \ 67 | MBIMCLI_ENUM_LIST_ITEM (MbimDefaultPduActivationHint, default_pdu_activation_hint, "default pdu activation hint") \ 68 | MBIMCLI_ENUM_LIST_ITEM (MbimAccessMediaType, access_media_type, "access media type") \ 69 | MBIMCLI_ENUM_LIST_ITEM (MbimNetworkIdleHintState, network_idle_hint_state, "network idle hint state") \ 70 | MBIMCLI_ENUM_LIST_ITEM (MbimEmergencyModeState, emergency_mode_state, "emergency mode state") \ 71 | MBIMCLI_ENUM_LIST_ITEM (MbimUiccSecureMessaging, uicc_secure_messaging, "uicc secure messaging") \ 72 | MBIMCLI_ENUM_LIST_ITEM (MbimUiccClassByteType, uicc_class_byte_type, "uicc class byte type") \ 73 | MBIMCLI_ENUM_LIST_ITEM (MbimUiccPassThroughAction, uicc_pass_through_action, "uicc pass through action") \ 74 | MBIMCLI_ENUM_LIST_ITEM (MbimIntelBootMode, intel_boot_mode, "intel boot mode") \ 75 | MBIMCLI_ENUM_LIST_ITEM (MbimTraceCommand, trace_command, "trace command") \ 76 | MBIMCLI_ENUM_LIST_ITEM (MbimSmsFlag, sms_flag, "sms flag") \ 77 | MBIMCLI_ENUM_LIST_ITEM (MbimQuectelCommandType, quectel_command_type, "quectel command type") \ 78 | MBIMCLI_ENUM_LIST_ITEM (MbimLteAttachContextOperation, lte_attach_context_operation, "lte attach context operation") \ 79 | MBIMCLI_ENUM_LIST_ITEM (MbimLteAttachContextRoamingControl, lte_attach_context_roaming_control, "lte attach context roaming control") \ 80 | MBIMCLI_ENUM_LIST_ITEM (MbimRegisterAction, register_action, "register action") 81 | 82 | #define MBIMCLI_ENUM_LIST_ITEM(TYPE,TYPE_UNDERSCORE,DESCR) \ 83 | gboolean mbimcli_read_## TYPE_UNDERSCORE ##_from_string (const gchar *str, TYPE *out, GError **error); 84 | MBIMCLI_ENUM_LIST 85 | #undef MBIMCLI_ENUM_LIST_ITEM 86 | 87 | /* Common helpers to read flags from strings */ 88 | 89 | #define MBIMCLI_FLAGS_LIST \ 90 | MBIMCLI_FLAGS_LIST_ITEM (MbimDataClass, data_class, "data class") 91 | 92 | #define MBIMCLI_FLAGS_LIST_ITEM(TYPE,TYPE_UNDERSCORE,DESCR) \ 93 | gboolean mbimcli_read_## TYPE_UNDERSCORE ##_mask_from_string (const gchar *str, TYPE *out, GError **error); 94 | MBIMCLI_FLAGS_LIST 95 | #undef MBIMCLI_FLAGS_LIST_ITEM 96 | 97 | #endif /* __MBIMCLI_H__ */ 98 | -------------------------------------------------------------------------------- /src/mbimcli/mbimcli-intel-at-tunnel.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * mbimcli -- Command line interface to control MBIM devices 5 | * 6 | * Copyright (C) 2023 chenhaotian 7 | */ 8 | 9 | #include "config.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #include "mbimcli.h" 22 | #include "mbimcli-helpers.h" 23 | 24 | /* Context */ 25 | typedef struct { 26 | MbimDevice *device; 27 | GCancellable *cancellable; 28 | } Context; 29 | static Context *ctx; 30 | 31 | /* Options */ 32 | static gchar *query_at_command_str; 33 | 34 | static GOptionEntry entries[] = { 35 | { "intel-at-tunnel-set-at-command", 0, 0, G_OPTION_ARG_STRING, &query_at_command_str, 36 | "send AT command to modem, and receive AT response", 37 | "\"\"" 38 | }, 39 | { NULL, 0, 0, 0, NULL, NULL, NULL } 40 | }; 41 | 42 | GOptionGroup * 43 | mbimcli_intel_at_tunnel_get_option_group (void) 44 | { 45 | GOptionGroup *group; 46 | 47 | group = g_option_group_new ("intel-at-tunnel", 48 | "Intel AT Tunnel options:", 49 | "Show Intel AT Tunnel Service options", 50 | NULL, 51 | NULL); 52 | g_option_group_add_entries (group, entries); 53 | return group; 54 | } 55 | 56 | gboolean 57 | mbimcli_intel_at_tunnel_options_enabled (void) 58 | { 59 | static guint n_actions = 0; 60 | static gboolean checked = FALSE; 61 | 62 | if (checked) 63 | return !!n_actions; 64 | 65 | n_actions = !!query_at_command_str; 66 | 67 | if (n_actions > 1) { 68 | g_printerr ("error: too many Intel AT Tunnel actions requested\n"); 69 | exit (EXIT_FAILURE); 70 | } 71 | 72 | checked = TRUE; 73 | return !!n_actions; 74 | } 75 | 76 | static void 77 | context_free (Context *context) 78 | { 79 | if (!context) 80 | return; 81 | 82 | if (context->cancellable) 83 | g_object_unref (context->cancellable); 84 | if (context->device) 85 | g_object_unref (context->device); 86 | g_slice_free (Context, context); 87 | } 88 | 89 | static void 90 | shutdown (gboolean operation_status) 91 | { 92 | /* Cleanup context and finish async operation */ 93 | context_free (ctx); 94 | mbimcli_async_operation_done (operation_status); 95 | } 96 | 97 | static void 98 | intel_at_tunnel_at_command_ready (MbimDevice *device, 99 | GAsyncResult *res) 100 | { 101 | g_autoptr(GError) error = NULL; 102 | guint32 ret_size = 0; 103 | const guint8 *ret_str = NULL; 104 | g_autoptr(MbimMessage) response = NULL; 105 | 106 | response = mbim_device_command_finish (device, res, &error); 107 | 108 | if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) { 109 | g_printerr ("error: operation failed: %s\n", error->message); 110 | shutdown (FALSE); 111 | return; 112 | } 113 | 114 | if (!mbim_message_intel_at_tunnel_at_command_response_parse ( 115 | response, 116 | &ret_size, 117 | &ret_str, 118 | &error)) { 119 | g_printerr ("error: couldn't parse response message: %s\n", error->message); 120 | shutdown (FALSE); 121 | return; 122 | } 123 | 124 | g_print ("%.*s\n", ret_size, ret_str); 125 | 126 | shutdown (TRUE); 127 | } 128 | 129 | void 130 | mbimcli_intel_at_tunnel_run (MbimDevice *device, 131 | GCancellable *cancellable) 132 | { 133 | g_autoptr(MbimMessage) request = NULL; 134 | g_autofree gchar *req_str = NULL; 135 | guint32 req_size = 0; 136 | 137 | /* Initialize context */ 138 | ctx = g_slice_new (Context); 139 | ctx->device = g_object_ref (device); 140 | ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; 141 | 142 | /* Request to send AT command */ 143 | if (query_at_command_str) { 144 | req_str = g_strdup_printf ("%s\r\n", query_at_command_str); 145 | req_size = strlen (req_str); 146 | 147 | request = mbim_message_intel_at_tunnel_at_command_set_new (req_size, (const guint8 *)req_str, NULL); 148 | mbim_device_command (ctx->device, 149 | request, 150 | 10, 151 | ctx->cancellable, 152 | (GAsyncReadyCallback)intel_at_tunnel_at_command_ready, 153 | NULL); 154 | return; 155 | } 156 | 157 | g_warn_if_reached (); 158 | } 159 | -------------------------------------------------------------------------------- /src/mbimcli/mbimcli-intel-firmware-update.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * mbimcli -- Command line interface to control MBIM devices 5 | * 6 | * Copyright 2018 Google LLC 7 | */ 8 | 9 | #include "config.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #include "mbimcli.h" 22 | #include "mbimcli-helpers.h" 23 | 24 | /* Context */ 25 | typedef struct { 26 | MbimDevice *device; 27 | GCancellable *cancellable; 28 | } Context; 29 | static Context *ctx; 30 | 31 | /* Options */ 32 | static gboolean modem_reboot_set; 33 | static gchar *modem_reboot_str; 34 | 35 | static gboolean modem_reboot_arg_parse (const gchar *option_name, 36 | const gchar *value, 37 | gpointer user_data, 38 | GError **error); 39 | 40 | static GOptionEntry entries[] = { 41 | { "intel-modem-reboot", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, G_CALLBACK (modem_reboot_arg_parse), 42 | "Reboot modem. Boot mode and timeout arguments only required if MBIMEx >= 2.0.", 43 | "[(Boot Mode),(Timeout)]" 44 | }, 45 | { NULL, 0, 0, 0, NULL, NULL, NULL } 46 | }; 47 | 48 | GOptionGroup * 49 | mbimcli_intel_firmware_update_get_option_group (void) 50 | { 51 | GOptionGroup *group; 52 | 53 | group = g_option_group_new ("intel-firmware-update", 54 | "Intel Firmware Update Service options:", 55 | "Show Intel Firmware Update Service options", 56 | NULL, 57 | NULL); 58 | g_option_group_add_entries (group, entries); 59 | 60 | return group; 61 | } 62 | 63 | static gboolean 64 | modem_reboot_arg_parse (const gchar *option_name, 65 | const gchar *value, 66 | gpointer user_data, 67 | GError **error) 68 | { 69 | modem_reboot_set = TRUE; 70 | modem_reboot_str = g_strdup (value); 71 | return TRUE; 72 | } 73 | 74 | gboolean 75 | mbimcli_intel_firmware_update_options_enabled (void) 76 | { 77 | static guint n_actions = 0; 78 | static gboolean checked = FALSE; 79 | 80 | if (checked) 81 | return !!n_actions; 82 | 83 | n_actions = modem_reboot_set; 84 | 85 | if (n_actions > 1) { 86 | g_printerr ("error: too many Intel Firmware Update Service actions requested\n"); 87 | exit (EXIT_FAILURE); 88 | } 89 | 90 | checked = TRUE; 91 | return !!n_actions; 92 | } 93 | 94 | static void 95 | context_free (Context *context) 96 | { 97 | if (!context) 98 | return; 99 | 100 | if (context->cancellable) 101 | g_object_unref (context->cancellable); 102 | if (context->device) 103 | g_object_unref (context->device); 104 | g_slice_free (Context, context); 105 | } 106 | 107 | static void 108 | shutdown (gboolean operation_status) 109 | { 110 | /* Cleanup context and finish async operation */ 111 | context_free (ctx); 112 | mbimcli_async_operation_done (operation_status); 113 | } 114 | 115 | static void 116 | modem_reboot_ready (MbimDevice *device, 117 | GAsyncResult *res) 118 | { 119 | g_autoptr(MbimMessage) response = NULL; 120 | g_autoptr(GError) error = NULL; 121 | 122 | response = mbim_device_command_finish (device, res, &error); 123 | if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) { 124 | g_printerr ("error: operation failed: %s\n", error->message); 125 | shutdown (FALSE); 126 | return; 127 | } 128 | 129 | g_print ("[%s] Successfully requested modem to reboot for firmware update\n\n", 130 | mbim_device_get_path_display (device)); 131 | 132 | shutdown (TRUE); 133 | } 134 | 135 | static gboolean 136 | modem_reboot_v2_input_parse (const gchar *str, 137 | MbimIntelBootMode *out_boot_mode, 138 | guint32 *out_timeout) 139 | { 140 | g_auto(GStrv) split = NULL; 141 | g_autoptr(GError) error = NULL; 142 | 143 | split = g_strsplit (modem_reboot_str, ",", -1); 144 | 145 | if (g_strv_length (split) > 2) { 146 | g_printerr ("error: couldn't parse input string, too many arguments\n"); 147 | return FALSE; 148 | } 149 | 150 | if (g_strv_length (split) < 2) { 151 | g_printerr ("error: couldn't parse input string, missing arguments\n"); 152 | return FALSE; 153 | } 154 | 155 | if (!mbimcli_read_intel_boot_mode_from_string (split[0], out_boot_mode, &error)) { 156 | g_printerr ("error: couldn't read boot mode: %s\n", error->message); 157 | return FALSE; 158 | } 159 | 160 | if (!mbimcli_read_uint_from_string (split[1], out_timeout)) { 161 | g_printerr ("error: couldn't read timeout value\n"); 162 | return FALSE; 163 | } 164 | 165 | return TRUE; 166 | } 167 | 168 | void 169 | mbimcli_intel_firmware_update_run (MbimDevice *device, 170 | GCancellable *cancellable) 171 | { 172 | g_autoptr(MbimMessage) request = NULL; 173 | 174 | /* Initialize context */ 175 | ctx = g_slice_new (Context); 176 | ctx->device = g_object_ref (device); 177 | ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; 178 | 179 | /* Request to reboot modem? */ 180 | if (modem_reboot_set) { 181 | if (mbim_device_check_ms_mbimex_version (device, 2, 0)) { 182 | MbimIntelBootMode boot_mode = MBIM_INTEL_BOOT_MODE_NORMAL_MODE; 183 | guint32 timeout = 0; 184 | 185 | if (!modem_reboot_v2_input_parse (modem_reboot_str, &boot_mode, &timeout)) { 186 | g_printerr ("error: couldn't parse input arguments\n"); 187 | g_printerr ("error: device in MBIMEx >= 2.0 requires boot mode and timeout arguments.\n"); 188 | shutdown (FALSE); 189 | return; 190 | } 191 | 192 | request = mbim_message_intel_firmware_update_v2_modem_reboot_set_new (boot_mode, timeout, NULL); 193 | } else { 194 | if (modem_reboot_str) { 195 | g_printerr ("error: arguments are not expected in MBIMEx < 2.0\n"); 196 | shutdown (FALSE); 197 | return; 198 | } 199 | 200 | g_debug ("Asynchronously rebooting modem..."); 201 | request = mbim_message_intel_firmware_update_modem_reboot_set_new (NULL); 202 | } 203 | 204 | mbim_device_command (ctx->device, 205 | request, 206 | 10, 207 | ctx->cancellable, 208 | (GAsyncReadyCallback)modem_reboot_ready, 209 | NULL); 210 | return; 211 | } 212 | 213 | g_warn_if_reached (); 214 | } 215 | -------------------------------------------------------------------------------- /src/mbimcli/mbimcli-intel-mutual-authentication.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * mbimcli -- Command line interface to control MBIM devices 5 | * 6 | * Copyright (C) 2022 Intel Corporation 7 | */ 8 | 9 | #include "config.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | #include "mbim-common.h" 23 | #include "mbimcli.h" 24 | #include "mbimcli-helpers.h" 25 | 26 | /* Context */ 27 | typedef struct { 28 | MbimDevice *device; 29 | GCancellable *cancellable; 30 | } Context; 31 | static Context *ctx; 32 | 33 | /* Options */ 34 | static gboolean query_fcc_lock_flag; 35 | static gchar *set_fcc_lock_str; 36 | 37 | static GOptionEntry entries[] = { 38 | { "intel-query-fcc-lock", 0, 0, G_OPTION_ARG_NONE, &query_fcc_lock_flag, 39 | "Query FCC lock information", 40 | NULL 41 | }, 42 | { "intel-set-fcc-lock", 0, 0, G_OPTION_ARG_STRING, &set_fcc_lock_str, 43 | "Set FCC lock information", 44 | "[(ResponsePresent),(Response)]" 45 | }, 46 | { NULL, 0, 0, 0, NULL, NULL, NULL } 47 | }; 48 | 49 | GOptionGroup * 50 | mbimcli_intel_mutual_authentication_get_option_group (void) 51 | { 52 | GOptionGroup *group; 53 | 54 | group = g_option_group_new ("intel-mutual-authentication", 55 | "Intel mutual authentication Service options:", 56 | "Show Intel mutual authentication Service options", 57 | NULL, 58 | NULL); 59 | g_option_group_add_entries (group, entries); 60 | 61 | return group; 62 | } 63 | 64 | gboolean 65 | mbimcli_intel_mutual_authentication_options_enabled (void) 66 | { 67 | static guint n_actions = 0; 68 | static gboolean checked = FALSE; 69 | 70 | if (checked) 71 | return !!n_actions; 72 | 73 | n_actions = (query_fcc_lock_flag + 74 | !!set_fcc_lock_str); 75 | 76 | if (n_actions > 1) { 77 | g_printerr ("error: too many Intel mutual Authentication actions requested\n"); 78 | exit (EXIT_FAILURE); 79 | } 80 | 81 | checked = TRUE; 82 | return !!n_actions; 83 | } 84 | 85 | static void 86 | context_free (Context *context) 87 | { 88 | if (!context) 89 | return; 90 | 91 | if (context->cancellable) 92 | g_object_unref (context->cancellable); 93 | if (context->device) 94 | g_object_unref (context->device); 95 | g_slice_free (Context, context); 96 | } 97 | 98 | static void 99 | shutdown (gboolean operation_status) 100 | { 101 | /* Cleanup context and finish async operation */ 102 | context_free (ctx); 103 | mbimcli_async_operation_done (operation_status); 104 | } 105 | 106 | static void 107 | query_fcc_lock_ready (MbimDevice *device, 108 | GAsyncResult *res, 109 | gpointer user_data) 110 | { 111 | MbimMessage *response = NULL; 112 | GError *error = NULL; 113 | gboolean challenge_present = FALSE; 114 | guint32 challenge = 0; 115 | 116 | response = mbim_device_command_finish (device, res, &error); 117 | if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) { 118 | g_printerr ("error: operation failed: %s\n", error->message); 119 | shutdown (FALSE); 120 | return; 121 | } 122 | 123 | if (!mbim_message_intel_mutual_authentication_fcc_lock_response_parse (response, 124 | &challenge_present, 125 | &challenge, 126 | &error)) { 127 | g_printerr ("error: couldn't parse response message: %s\n", error->message); 128 | shutdown (FALSE); 129 | return; 130 | } 131 | 132 | g_print ("FCC lock status: %s\n", challenge_present ? "locked" : "unlocked"); 133 | if (challenge_present) 134 | g_print ("\tChallenge: %u\n", challenge); 135 | 136 | shutdown (TRUE); 137 | } 138 | 139 | void 140 | mbimcli_intel_mutual_authentication_run (MbimDevice *device, 141 | GCancellable *cancellable) 142 | { 143 | g_autoptr(MbimMessage) request = NULL; 144 | 145 | /* Initialize context */ 146 | ctx = g_slice_new (Context); 147 | ctx->device = g_object_ref (device); 148 | ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; 149 | 150 | /* Query FCC lock information */ 151 | if (query_fcc_lock_flag) { 152 | g_debug ("Asynchronously querying FCC lock information..."); 153 | 154 | request = mbim_message_intel_mutual_authentication_fcc_lock_query_new (NULL); 155 | mbim_device_command (ctx->device, 156 | request, 157 | 10, 158 | ctx->cancellable, 159 | (GAsyncReadyCallback)query_fcc_lock_ready, 160 | NULL); 161 | return; 162 | } 163 | 164 | /* Set FCC lock information */ 165 | if (set_fcc_lock_str) { 166 | gboolean response_present = FALSE; 167 | guint32 response = 0; 168 | g_auto(GStrv) split = NULL; 169 | 170 | split = g_strsplit (set_fcc_lock_str, ",", -1); 171 | 172 | if (g_strv_length (split) < 2) { 173 | g_printerr ("error: couldn't parse input arguments, missing arguments\n"); 174 | shutdown (FALSE); 175 | return; 176 | } 177 | 178 | if (g_strv_length (split) > 2) { 179 | g_printerr ("error: couldn't parse input arguments, too many arguments\n"); 180 | shutdown (FALSE); 181 | return; 182 | } 183 | 184 | if (!mbimcli_read_boolean_from_string (split[0], &response_present)) { 185 | g_printerr ("error: couldn't parse input, wrong value given\n"); 186 | shutdown (FALSE); 187 | return; 188 | } 189 | 190 | if (!mbimcli_read_uint_from_string (split[1], &response)) { 191 | g_printerr ("error: couldn't parse input, wrong value given\n"); 192 | shutdown (FALSE); 193 | return; 194 | } 195 | 196 | request = mbim_message_intel_mutual_authentication_fcc_lock_set_new (response_present, response, NULL); 197 | mbim_device_command (ctx->device, 198 | request, 199 | 10, 200 | ctx->cancellable, 201 | (GAsyncReadyCallback)query_fcc_lock_ready, 202 | NULL); 203 | return; 204 | } 205 | g_warn_if_reached (); 206 | } 207 | -------------------------------------------------------------------------------- /src/mbimcli/mbimcli-ms-firmware-id.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * mbimcli -- Command line interface to control MBIM devices 5 | * 6 | * Copyright (C) 2014 Google, Inc. 7 | */ 8 | 9 | #include "config.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #include "mbimcli.h" 22 | 23 | /* Context */ 24 | typedef struct { 25 | MbimDevice *device; 26 | GCancellable *cancellable; 27 | } Context; 28 | static Context *ctx; 29 | 30 | /* Options */ 31 | static gboolean query_firmware_id_flag; 32 | 33 | static GOptionEntry entries[] = { 34 | { "ms-query-firmware-id", 0, 0, G_OPTION_ARG_NONE, &query_firmware_id_flag, 35 | "Query firmware ID", 36 | NULL 37 | }, 38 | { NULL, 0, 0, 0, NULL, NULL, NULL } 39 | }; 40 | 41 | GOptionGroup * 42 | mbimcli_ms_firmware_id_get_option_group (void) 43 | { 44 | GOptionGroup *group; 45 | 46 | group = g_option_group_new ("ms-firmware-id", 47 | "Microsoft Firmware ID options:", 48 | "Show Microsoft Firmware ID Service options", 49 | NULL, 50 | NULL); 51 | g_option_group_add_entries (group, entries); 52 | 53 | return group; 54 | } 55 | 56 | gboolean 57 | mbimcli_ms_firmware_id_options_enabled (void) 58 | { 59 | static guint n_actions = 0; 60 | static gboolean checked = FALSE; 61 | 62 | if (checked) 63 | return !!n_actions; 64 | 65 | n_actions = query_firmware_id_flag; 66 | 67 | if (n_actions > 1) { 68 | g_printerr ("error: too many Microsoft Firmware ID actions requested\n"); 69 | exit (EXIT_FAILURE); 70 | } 71 | 72 | checked = TRUE; 73 | return !!n_actions; 74 | } 75 | 76 | static void 77 | context_free (Context *context) 78 | { 79 | if (!context) 80 | return; 81 | 82 | if (context->cancellable) 83 | g_object_unref (context->cancellable); 84 | if (context->device) 85 | g_object_unref (context->device); 86 | g_slice_free (Context, context); 87 | } 88 | 89 | static void 90 | shutdown (gboolean operation_status) 91 | { 92 | /* Cleanup context and finish async operation */ 93 | context_free (ctx); 94 | mbimcli_async_operation_done (operation_status); 95 | } 96 | 97 | static void 98 | query_firmware_id_ready (MbimDevice *device, 99 | GAsyncResult *res) 100 | { 101 | g_autoptr(MbimMessage) response = NULL; 102 | g_autoptr(GError) error = NULL; 103 | const MbimUuid *firmware_id; 104 | g_autofree gchar *firmware_id_str = NULL; 105 | 106 | response = mbim_device_command_finish (device, res, &error); 107 | if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) { 108 | g_printerr ("error: operation failed: %s\n", error->message); 109 | shutdown (FALSE); 110 | return; 111 | } 112 | 113 | if (!mbim_message_ms_firmware_id_get_response_parse (response, &firmware_id, &error)) { 114 | g_printerr ("error: couldn't parse response message: %s\n", error->message); 115 | shutdown (FALSE); 116 | return; 117 | } 118 | 119 | firmware_id_str = firmware_id ? mbim_uuid_get_printable (firmware_id) : NULL; 120 | 121 | g_print ("[%s] Firmware ID retrieved: '%s'\n\n", 122 | mbim_device_get_path_display (device), 123 | VALIDATE_UNKNOWN (firmware_id_str)); 124 | 125 | shutdown (TRUE); 126 | } 127 | 128 | void 129 | mbimcli_ms_firmware_id_run (MbimDevice *device, 130 | GCancellable *cancellable) 131 | { 132 | g_autoptr(MbimMessage) request = NULL; 133 | 134 | /* Initialize context */ 135 | ctx = g_slice_new (Context); 136 | ctx->device = g_object_ref (device); 137 | ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; 138 | 139 | /* Request to get firmware ID? */ 140 | if (query_firmware_id_flag) { 141 | g_debug ("Asynchronously querying firmware ID..."); 142 | request = (mbim_message_ms_firmware_id_get_query_new (NULL)); 143 | mbim_device_command (ctx->device, 144 | request, 145 | 10, 146 | ctx->cancellable, 147 | (GAsyncReadyCallback)query_firmware_id_ready, 148 | NULL); 149 | return; 150 | } 151 | 152 | g_warn_if_reached (); 153 | } 154 | -------------------------------------------------------------------------------- /src/mbimcli/mbimcli-ms-host-shutdown.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * mbimcli -- Command line interface to control MBIM devices 5 | * 6 | * Copyright (C) 2014 Google, Inc. 7 | */ 8 | 9 | #include "config.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #include "mbimcli.h" 22 | 23 | /* Context */ 24 | typedef struct { 25 | MbimDevice *device; 26 | GCancellable *cancellable; 27 | } Context; 28 | static Context *ctx; 29 | 30 | /* Options */ 31 | static gboolean notify_host_shutdown_flag; 32 | 33 | static GOptionEntry entries[] = { 34 | { "ms-notify-host-shutdown", 0, 0, G_OPTION_ARG_NONE, ¬ify_host_shutdown_flag, 35 | "Notify that host is shutting down", 36 | NULL 37 | }, 38 | { NULL, 0, 0, 0, NULL, NULL, NULL } 39 | }; 40 | 41 | GOptionGroup * 42 | mbimcli_ms_host_shutdown_get_option_group (void) 43 | { 44 | GOptionGroup *group; 45 | 46 | group = g_option_group_new ("ms-host-shutdown", 47 | "Microsoft Host Shutdown options:", 48 | "Show Microsoft Host Shutdown Service options", 49 | NULL, 50 | NULL); 51 | g_option_group_add_entries (group, entries); 52 | 53 | return group; 54 | } 55 | 56 | gboolean 57 | mbimcli_ms_host_shutdown_options_enabled (void) 58 | { 59 | static guint n_actions = 0; 60 | static gboolean checked = FALSE; 61 | 62 | if (checked) 63 | return !!n_actions; 64 | 65 | n_actions = notify_host_shutdown_flag; 66 | 67 | if (n_actions > 1) { 68 | g_printerr ("error: too many Microsoft Host Shutdown actions requested\n"); 69 | exit (EXIT_FAILURE); 70 | } 71 | 72 | checked = TRUE; 73 | return !!n_actions; 74 | } 75 | 76 | static void 77 | context_free (Context *context) 78 | { 79 | if (!context) 80 | return; 81 | 82 | if (context->cancellable) 83 | g_object_unref (context->cancellable); 84 | if (context->device) 85 | g_object_unref (context->device); 86 | g_slice_free (Context, context); 87 | } 88 | 89 | static void 90 | shutdown (gboolean operation_status) 91 | { 92 | /* Cleanup context and finish async operation */ 93 | context_free (ctx); 94 | mbimcli_async_operation_done (operation_status); 95 | } 96 | 97 | static void 98 | ms_host_shutdown_ready (MbimDevice *device, 99 | GAsyncResult *res) 100 | { 101 | g_autoptr(MbimMessage) response = NULL; 102 | g_autoptr(GError) error = NULL; 103 | 104 | response = mbim_device_command_finish (device, res, &error); 105 | if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) { 106 | g_printerr ("error: operation failed: %s\n", error->message); 107 | shutdown (FALSE); 108 | return; 109 | } 110 | 111 | g_print ("[%s] Successfully notified that host is shutting down\n\n", 112 | mbim_device_get_path_display (device)); 113 | 114 | shutdown (TRUE); 115 | } 116 | 117 | void 118 | mbimcli_ms_host_shutdown_run (MbimDevice *device, 119 | GCancellable *cancellable) 120 | { 121 | g_autoptr(MbimMessage) request = NULL; 122 | 123 | /* Initialize context */ 124 | ctx = g_slice_new (Context); 125 | ctx->device = g_object_ref (device); 126 | ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; 127 | 128 | /* Request to notify that host is shutting down */ 129 | if (notify_host_shutdown_flag) { 130 | g_debug ("Asynchronously notifying host is shutting down..."); 131 | request = (mbim_message_ms_host_shutdown_notify_set_new (NULL)); 132 | mbim_device_command (ctx->device, 133 | request, 134 | 10, 135 | ctx->cancellable, 136 | (GAsyncReadyCallback)ms_host_shutdown_ready, 137 | NULL); 138 | return; 139 | } 140 | 141 | g_warn_if_reached (); 142 | } 143 | -------------------------------------------------------------------------------- /src/mbimcli/mbimcli-ms-voice-extensions.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * mbimcli -- Command line interface to control MBIM devices 5 | * 6 | * Copyright (C) 2022 Intel Corporation 7 | */ 8 | 9 | #include "config.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | #include "mbim-common.h" 23 | #include "mbimcli.h" 24 | #include "mbimcli-helpers.h" 25 | 26 | /* Context */ 27 | typedef struct { 28 | MbimDevice *device; 29 | GCancellable *cancellable; 30 | } Context; 31 | static Context *ctx; 32 | 33 | /* Options */ 34 | static gboolean query_nitz_flag; 35 | 36 | static GOptionEntry entries[] = { 37 | { "ms-query-nitz", 0, 0, G_OPTION_ARG_NONE, &query_nitz_flag, 38 | "Query network identity and time zone", 39 | NULL 40 | }, 41 | { NULL, 0, 0, 0, NULL, NULL, NULL } 42 | }; 43 | 44 | GOptionGroup * 45 | mbimcli_ms_voice_extensions_get_option_group (void) 46 | { 47 | GOptionGroup *group; 48 | 49 | group = g_option_group_new ("ms-voice-extensions", 50 | "Microsoft Voice Extensions Service options:", 51 | "Show Microsoft Voice Extensions Service options", 52 | NULL, 53 | NULL); 54 | g_option_group_add_entries (group, entries); 55 | 56 | return group; 57 | } 58 | 59 | gboolean 60 | mbimcli_ms_voice_extensions_options_enabled (void) 61 | { 62 | static guint n_actions = 0; 63 | static gboolean checked = FALSE; 64 | 65 | if (checked) 66 | return !!n_actions; 67 | 68 | n_actions = query_nitz_flag; 69 | 70 | if (n_actions > 1) { 71 | g_printerr ("error: too many Microsoft Voice Extensions Service actions requested\n"); 72 | exit (EXIT_FAILURE); 73 | } 74 | 75 | checked = TRUE; 76 | return !!n_actions; 77 | } 78 | 79 | static void 80 | context_free (Context *context) 81 | { 82 | if (!context) 83 | return; 84 | 85 | if (context->cancellable) 86 | g_object_unref (context->cancellable); 87 | if (context->device) 88 | g_object_unref (context->device); 89 | g_slice_free (Context, context); 90 | } 91 | 92 | static void 93 | shutdown (gboolean operation_status) 94 | { 95 | /* Cleanup context and finish async operation */ 96 | context_free (ctx); 97 | mbimcli_async_operation_done (operation_status); 98 | } 99 | 100 | static void 101 | query_nitz_ready (MbimDevice *device, 102 | GAsyncResult *res) 103 | { 104 | g_autoptr(MbimMessage) response = NULL; 105 | g_autoptr(GError) error = NULL; 106 | guint32 day = 0; 107 | guint32 month = 0; 108 | guint32 year = 0; 109 | guint32 hour = 0; 110 | guint32 minutes = 0; 111 | guint32 second = 0; 112 | guint32 time_zone_offset_minutes = 0; 113 | guint32 daylight_saving_time_offset_minutes = 0; 114 | MbimDataClass data_class; 115 | g_autofree gchar *data_class_str = NULL; 116 | 117 | response = mbim_device_command_finish (device, res, &error); 118 | if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) { 119 | g_printerr ("error: operation failed: %s\n", error->message); 120 | shutdown (FALSE); 121 | return; 122 | } 123 | 124 | if (!mbim_message_ms_voice_extensions_nitz_response_parse ( 125 | response, 126 | &year, 127 | &month, 128 | &day, 129 | &hour, 130 | &minutes, 131 | &second, 132 | &time_zone_offset_minutes, 133 | &daylight_saving_time_offset_minutes, 134 | &data_class, 135 | &error)) { 136 | g_printerr ("error: couldn't parse response message: %s\n", error->message); 137 | shutdown (FALSE); 138 | return; 139 | } 140 | 141 | data_class_str = mbim_data_class_build_string_from_mask (data_class); 142 | 143 | g_print ("Successfully queried NITZ info from modem:\n" 144 | "\t Date: %02u/%02u/%u\n" 145 | "\t Time: %02u:%02u:%02u\n" 146 | "\t Time zone offset minutes: %u\n" 147 | "\tDaylight saving time offset minutes: %u\n" 148 | "\t Data class: %s\n", 149 | day, 150 | month, 151 | year, 152 | hour, 153 | minutes, 154 | second, 155 | time_zone_offset_minutes, 156 | daylight_saving_time_offset_minutes, 157 | VALIDATE_UNKNOWN (data_class_str)); 158 | 159 | shutdown (TRUE); 160 | } 161 | 162 | void 163 | mbimcli_ms_voice_extensions_run (MbimDevice *device, 164 | GCancellable *cancellable) 165 | { 166 | g_autoptr(MbimMessage) request = NULL; 167 | 168 | /* Initialize context */ 169 | ctx = g_slice_new (Context); 170 | ctx->device = g_object_ref (device); 171 | ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; 172 | 173 | /* Request to reboot modem? */ 174 | if (query_nitz_flag) { 175 | g_debug ("Asynchronously querying nitz info..."); 176 | request = mbim_message_ms_voice_extensions_nitz_query_new (NULL); 177 | mbim_device_command (ctx->device, 178 | request, 179 | 10, 180 | ctx->cancellable, 181 | (GAsyncReadyCallback)query_nitz_ready, 182 | NULL); 183 | return; 184 | } 185 | 186 | g_warn_if_reached (); 187 | } 188 | -------------------------------------------------------------------------------- /src/mbimcli/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | deps = [ 5 | libmbim_common_dep, 6 | libmbim_glib_dep, 7 | ] 8 | 9 | helpers_sources = files( 10 | 'mbimcli-helpers.c', 11 | 'mbimcli-helpers-quectel.c', 12 | ) 13 | 14 | mbimcli_helpers = static_library( 15 | 'mbimcli-helpers', 16 | sources: helpers_sources, 17 | include_directories: ['.', top_inc], 18 | dependencies: deps, 19 | ) 20 | 21 | mbimcli_helpers_dep = declare_dependency( 22 | include_directories: ['.', top_inc], 23 | dependencies: deps, 24 | link_with: mbimcli_helpers, 25 | ) 26 | 27 | mbimcli_sources = files( 28 | 'mbimcli.c', 29 | 'mbimcli-atds.c', 30 | 'mbimcli-basic-connect.c', 31 | 'mbimcli-compal.c', 32 | 'mbimcli-dss.c', 33 | 'mbimcli-fibocom.c', 34 | 'mbimcli-google.c', 35 | 'mbimcli-intel-at-tunnel.c', 36 | 'mbimcli-intel-firmware-update.c', 37 | 'mbimcli-intel-mutual-authentication.c', 38 | 'mbimcli-intel-thermal-rf.c', 39 | 'mbimcli-intel-tools.c', 40 | 'mbimcli-link-management.c', 41 | 'mbimcli-ms-basic-connect-extensions.c', 42 | 'mbimcli-ms-firmware-id.c', 43 | 'mbimcli-ms-host-shutdown.c', 44 | 'mbimcli-ms-sar.c', 45 | 'mbimcli-ms-uicc-low-level-access.c', 46 | 'mbimcli-ms-voice-extensions.c', 47 | 'mbimcli-phonebook.c', 48 | 'mbimcli-quectel.c', 49 | 'mbimcli-sms.c', 50 | ) 51 | 52 | sources = mbimcli_sources + helpers_sources + files( 53 | 'mbimcli-link-management.c', 54 | ) 55 | 56 | mbimcli = executable( 57 | 'mbimcli', 58 | sources: sources, 59 | include_directories: top_inc, 60 | dependencies: deps, 61 | install: true, 62 | ) 63 | 64 | if enable_bash_completion 65 | install_data( 66 | 'mbimcli', 67 | install_dir: bash_completion_completionsdir, 68 | ) 69 | endif 70 | 71 | subdir('tests') 72 | -------------------------------------------------------------------------------- /src/mbimcli/tests/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2025 Dan Williams 3 | 4 | test_units = [ 5 | 'quectel', 6 | ] 7 | 8 | test_env = { 9 | 'G_DEBUG': 'gc-friendly', 10 | 'MALLOC_CHECK_': '2', 11 | 'G_TEST_SRCDIR': meson.current_source_dir(), 12 | 'G_TEST_BUILDDIR': meson.current_build_dir(), 13 | } 14 | 15 | foreach test_unit: test_units 16 | test_name = 'test-' + test_unit 17 | 18 | exe = executable( 19 | test_name, 20 | sources: test_name + '.c', 21 | include_directories: top_inc, 22 | dependencies: mbimcli_helpers_dep, 23 | ) 24 | 25 | test( 26 | test_unit, 27 | exe, 28 | env: test_env, 29 | ) 30 | endforeach 31 | -------------------------------------------------------------------------------- /src/mbimcli/tests/test-quectel.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 3 | /* 4 | * Copyright (C) 2025 Dan Williams 5 | */ 6 | 7 | #include 8 | 9 | #include "mbimcli-helpers-quectel.h" 10 | 11 | #define UNSET_CMD_TYPE 999 12 | 13 | typedef struct { 14 | const gchar *name; 15 | const gchar *type_str; 16 | const gchar *cmd_str; 17 | const MbimQuectelCommandType expected_cmd_type; 18 | gboolean expect_error; 19 | } testcase; 20 | 21 | static void 22 | test_set_command_input_parse_common (gconstpointer user_data) 23 | { 24 | const testcase *tc = user_data; 25 | g_autofree gchar *input_str = NULL; 26 | g_autofree gchar *parsed_cmd = NULL; 27 | MbimQuectelCommandType parsed_type = UNSET_CMD_TYPE; 28 | gboolean success; 29 | 30 | if (tc->type_str != NULL) { 31 | input_str = g_strdup_printf("%s,%s", tc->type_str, tc->cmd_str); 32 | } else { 33 | input_str = g_strdup (tc->cmd_str); 34 | } 35 | success = mbimcli_helpers_quectel_set_command_input_parse (input_str, 36 | &parsed_cmd, 37 | &parsed_type); 38 | g_assert (success != tc->expect_error); 39 | if (!tc->expect_error) { 40 | g_assert_cmpstr (parsed_cmd, ==, tc->cmd_str); 41 | } 42 | g_assert_cmpuint (parsed_type, ==, tc->expected_cmd_type); 43 | } 44 | 45 | int main (int argc, char **argv) 46 | { 47 | gsize i; 48 | const testcase test_data[] = { 49 | /* Untyped AT commands */ 50 | { 51 | .name = "no-type", 52 | .cmd_str = "at+cversion;+qgmr;+csub", 53 | .expected_cmd_type = UNSET_CMD_TYPE, 54 | }, 55 | { 56 | .name = "no-type-commas", 57 | .cmd_str = "at+qcfg=\"usbcfg\",0x2C7C,0x6008,0x00FF", 58 | .expected_cmd_type = UNSET_CMD_TYPE, 59 | }, 60 | { 61 | .name = "bad-no-type", 62 | .cmd_str = "bm+cversion;+qgmr;+csub", 63 | .expected_cmd_type = UNSET_CMD_TYPE, 64 | .expect_error = TRUE, 65 | }, 66 | /* AT-type AT commands */ 67 | { 68 | .name = "at-type", 69 | .type_str = "at", 70 | .cmd_str = "at+cversion;+qgmr;+csub", 71 | .expected_cmd_type = MBIM_QUECTEL_COMMAND_TYPE_AT, 72 | }, 73 | { 74 | .name = "at-type-commas", 75 | .type_str = "at", 76 | .cmd_str = "at+qcfg=\"usbcfg\",0x2C7C,0x6008,0x00FF", 77 | .expected_cmd_type = MBIM_QUECTEL_COMMAND_TYPE_AT, 78 | }, 79 | { 80 | .name = "bad-at-type", 81 | .type_str = "at", 82 | .cmd_str = "bm+cversion;+qgmr;+csub", 83 | .expected_cmd_type = UNSET_CMD_TYPE, 84 | .expect_error = TRUE, 85 | }, 86 | }; 87 | 88 | g_test_init (&argc, &argv, NULL); 89 | 90 | for (i = 0; i < G_N_ELEMENTS(test_data); i++) { 91 | g_autofree gchar *test_desc; 92 | 93 | test_desc = g_strdup_printf("/mbimcli/quectel/set-command-input-parse/%s", test_data[i].name); 94 | g_test_add_data_func (test_desc, &test_data[i], test_set_command_input_parse_common); 95 | } 96 | 97 | return g_test_run (); 98 | } 99 | -------------------------------------------------------------------------------- /src/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | subdir('common') 5 | subdir('libmbim-glib') 6 | subdir('mbimcli') 7 | subdir('mbim-proxy') 8 | -------------------------------------------------------------------------------- /utils/meson.build: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # Copyright (C) 2021 Iñigo Martinez 3 | 4 | mbim_network = configure_file( 5 | input: 'mbim-network.in', 6 | output: '@BASENAME@', 7 | configuration: version_conf, 8 | install_dir: mbim_bindir, 9 | install_mode: 'rwxr-xr-x', 10 | ) 11 | --------------------------------------------------------------------------------