From: taeyoung Date: Fri, 2 Sep 2016 01:02:12 +0000 (+0900) Subject: common: remove unused codes X-Git-Tag: submit/tizen/20160905.095524^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3e223c3439e5e9ce6f4585ee91b0b4815abf892a;p=platform%2Fcore%2Fapi%2Fusb-host.git common: remove unused codes - test dir, example dir: they are not included to image. Thus they need to be removed - others: Unused codes should be removed Change-Id: I7518ec23f6e64b268a6811e758761ac23ae6baa0 Signed-off-by: taeyoung --- diff --git a/AUTHORS b/AUTHORS index ae94397..e488df1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,2 +1,3 @@ Stanislaw Wadas Jan Cybulski +Paweł Szewczyk diff --git a/CMakeLists.txt b/CMakeLists.txt index 00fb460..3fabc8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,6 @@ PROJECT(capi-system-usbhost) # Generation options: # -DBUILD_DOC_ONLY - only doxygen documentation is build # -DBUILD_DOC - build also doxygen documentation -# -DBUILD_EXAMPLES - build also sample applications -# -DBUILD_TESTS - build also tests ######################################################## ######################################################## @@ -23,12 +21,6 @@ ENDIF(BUILD_DOC_ONLY) SET(LIBNAME ${PROJECT_NAME}) -IF(BUILD_TESTS) - SET(PKG_MODULES - ${PKG_MODULES} cmocka>=1.0 - ) -ENDIF() - IF(BUILD_SHARED_LIBS) SET(PKG_MODULES ${PKG_MODULES} @@ -51,7 +43,6 @@ IF(BUILD_SHARED_LIBS) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(PACKAGE ${PROJECT_NAME}) - SET(LIBDIR "${PREFIX}/lib") SET(INCLUDEDIR "${PREFIX}/include") SET(DATADIR "${PREFIX}/share/${PACKAGE}/data") @@ -72,7 +63,7 @@ IF(BUILD_SHARED_LIBS) INSTALL(FILES include/usb_host.h DESTINATION ${INCLUDEDIR}/) INSTALL(FILES src/40-usb.rules DESTINATION /usr/lib/udev/rules.d) - INSTALL(TARGETS ${LIBNAME} DESTINATION ${LIBDIR}) + INSTALL(TARGETS ${LIBNAME} DESTINATION ${LIB_INSTALL_DIR}) CONFIGURE_FILE(${LIBNAME}.pc.in ${LIBNAME}.pc @ONLY) INSTALL(FILES ${CMAKE_BINARY_DIR}/${LIBNAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) @@ -87,8 +78,6 @@ IF(BUILD_SHARED_LIBS) COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) - ADD_SUBDIRECTORY(pc) - ENDIF(BUILD_SHARED_LIBS) IF(BUILD_DOC) @@ -117,38 +106,3 @@ IF(BUILD_DOC) ) ENDIF(BUILD_DOC) - -IF(BUILD_TESTS) - ENABLE_TESTING() - SET( TESTS_SRCS - tests/usb_host_test.c - tests/libusb_wrap.c - src/usb_host.c - ) - - INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) - INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) - - FOREACH(flag ${pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") - ENDFOREACH(flag) - - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -Wall -lcmocka") - MESSAGE("FLAGS: ${CMAKE_C_FLAGS}") - MESSAGE("PKGS_LDFLAGS: ${pkgs_LDFLAGS}") - - ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") - ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"") - ADD_DEFINITIONS("-DLOCALEDIR=\"${LOCALEDIR}\"") - - SET(TESTS_SRCS - ${TESTS_SRCS} - ) - - ADD_EXECUTABLE(${PROJECT_NAME}-tests ${TESTS_SRCS}) - TARGET_LINK_LIBRARIES(${PROJECT_NAME}-tests ${pkgs_LDFLAGS}) - ADD_TEST(NAME ${PROJECT_NAME}-tests COMMAND ${PROJECT_NAME}-tests) - - ADD_DEFINITIONS("-DGD_EXPORT_SYMBOLS") - -ENDIF(BUILD_TESTS) diff --git a/ChangeLog b/ChangeLog deleted file mode 100644 index 9dfab22..0000000 --- a/ChangeLog +++ /dev/null @@ -1,2 +0,0 @@ -Tue, 15 May 2015 Stanislaw Wadas 0.0.1 -- Initial release diff --git a/INSTALL b/INSTALL deleted file mode 100644 index 4238270..0000000 --- a/INSTALL +++ /dev/null @@ -1 +0,0 @@ -TODO add install note diff --git a/README b/README deleted file mode 100644 index 60be051..0000000 --- a/README +++ /dev/null @@ -1 +0,0 @@ -Library that provides CAPI for raw USB communication. diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt deleted file mode 100644 index 79ab757..0000000 --- a/example/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - -SET(USBHOST_TEST "usbhost-test") - -INCLUDE(FindPkgConfig) -pkg_check_modules(${USBHOST_TEST}_pkgs REQUIRED - capi-system-usbhost -) - -FOREACH(flag ${${USBHOST_TEST}_pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag} -g") -ENDFOREACH(flag) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -O0 -Wall") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") - -SET(LSDEV "lsdev") -SET(LSDEV_SRCS lsdev.c) -ADD_EXECUTABLE(${LSDEV} ${LSDEV_SRCS}) -TARGET_LINK_LIBRARIES(${LSDEV} ${${USBHOST_TEST}_pkgs_LDFLAGS}) -INSTALL(TARGETS ${LSDEV} DESTINATION bin) - -SET(SIMPLE_SYNC "simple_sync") -SET(SIMPLE_SYNC_SRCS simple_sync.c) -ADD_EXECUTABLE(${SIMPLE_SYNC} ${SIMPLE_SYNC_SRCS}) -TARGET_LINK_LIBRARIES(${SIMPLE_SYNC} ${${USBHOST_TEST}_pkgs_LDFLAGS}) -INSTALL(TARGETS ${SIMPLE_SYNC} DESTINATION bin) diff --git a/example/LICENSE b/example/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/example/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/example/lsdev.c b/example/lsdev.c deleted file mode 100644 index 441b223..0000000 --- a/example/lsdev.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * lsdev.c - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include - -#define PORT_NUMBERS 8 -#define BUF_SIZE 256 - -static void print_devs(usb_host_device_h *devs, usb_host_context_h ctx) -{ - usb_host_device_h dev; - int i = 0, j = 0; - int path[PORT_NUMBERS]; - int r; - int vid, pid, bus, addr, len; - - int data1; - char str1[BUF_SIZE]; - usb_host_config_h conf; - usb_host_interface_h iface; - - printf("Getting device list: \n"); - - while ((dev = devs[i++]) != NULL) { - r = usb_host_device_get_id_vendor(dev, &vid); - if (r < 0) { - printf("Cannot get vendor id"); - return; - } - - r = usb_host_device_get_id_product(dev, &pid); - if (r < 0) { - printf("Cannot get product id"); - return; - } - - r = usb_host_device_get_bus_number(dev, &bus); - if (r < 0) { - printf("Cannot get bus number"); - return; - } - - r = usb_host_device_get_address(dev, &addr); - if (r < 0) { - printf("Cannot get device address"); - return; - } - - printf("%04x:%04x (bus %d, device %d)", vid, pid, bus, addr); - - len = 8; - r = usb_host_device_get_port_numbers(dev, path, PORT_NUMBERS, &len); - if (r < 0) - printf("cant get port numbers\n"); - else { - printf(" path: %d", path[0]); - for (j = 1; j < len; j++) - printf(".%d", path[j]); - } - printf("\n"); - } - - printf("provide vid and pid of device which you want to operate on\n"); - printf("\n enter device vid and hit enter(with 0x):"); - scanf("%x", &vid); - printf("\n enter device pid and hit enter(with 0x):"); - scanf("%x", &pid); - - printf("\nOpening device vid:0x%x pid:0x%x\n", vid, pid); - - r = usb_host_device_open_with_vid_pid(ctx, vid, pid, &dev); - if (r < 0) { - printf("cant get dev with vid pid\n"); - return; - } - printf("opened\n"); - - r = usb_host_device_get_max_packet_size_0(dev, &data1); - if (r < 0) { - printf("ERROR: %s", strerror(r)); - return; - } - - printf("\nmax packet size: %d\n", data1); - - r = usb_host_get_active_config(dev, &conf); - if (r < 0) { - printf("ERROR: %s", strerror(r)); - return; - } - - r = usb_host_device_get_config(dev, 1, &conf); - - printf("\ntrying to set 2nd config\n"); - r = usb_host_set_config(conf); - if (r < 0) - printf("failure\n"); - - r = usb_host_config_get_interface(conf, 0, &iface); - if (r < 0) - printf("failure\n"); - - printf("claiming iface\n"); - r = usb_host_claim_interface(iface, 1); - if (r < 0) - printf("failure\n"); - - printf("releasing iface\n"); - r = usb_host_release_interface(iface); - if (r < 0) - printf("failure\n"); - - len = BUF_SIZE; - r = usb_host_device_get_product_str(dev, &len, str1); - if (r < 0) - printf("failure\n"); - else - printf("Product name: %s\n", str1); - - len = BUF_SIZE; - r = usb_host_device_get_manufacturer_str(dev, &len, str1); - if (r < 0) - printf("failure\n"); - else - printf("Manufacturer name: %s\n", str1); - - usb_host_config_destroy(conf); - usb_host_device_close(dev); -} - -int main(void) -{ - usb_host_context_h ctx; - usb_host_device_h *devs; - int r; - int cnt; - - r = usb_host_create(&ctx); - if (r < 0) { - printf("ERROR: %s", strerror(r)); - return r; - } - - r = usb_host_get_device_list(ctx, &devs, &cnt); - if (r < 0) - return r; - - print_devs(devs, ctx); - usb_host_free_device_list(devs, 1); - - usb_host_destroy(ctx); - - return 0; -} diff --git a/example/packaging/usbhost-test.manifest b/example/packaging/usbhost-test.manifest deleted file mode 100644 index 97e8c31..0000000 --- a/example/packaging/usbhost-test.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/example/packaging/usbhost-test.spec b/example/packaging/usbhost-test.spec deleted file mode 100644 index 95f5ff6..0000000 --- a/example/packaging/usbhost-test.spec +++ /dev/null @@ -1,43 +0,0 @@ -Name: usbhost-test -Summary: test app for usb host apis -Version: 0.0.1 -Release: 1 -Group: System/Libraries -License: Apache License, Version 2.0 -Source0: %{name}-%{version}.tar.gz -Source1001: %{name}.manifest -BuildRequires: cmake -BuildRequires: pkgconfig(capi-system-usbhost) -BuildRequires: pkgconfig(capi-base-common) - -Requires(post): /sbin/ldconfig -Requires(postun): /sbin/ldconfig - -%description - -%prep -%setup -q -cp %{SOURCE1001} . - -%build -cmake . -DCMAKE_INSTALL_PREFIX=/usr - -make %{?jobs:-j%jobs} - -%install -rm -rf %{buildroot} - -%make_install -mkdir -p %{buildroot}/usr/share/license -cp -f LICENSE %{buildroot}/usr/share/license/%{name} - -%post -p /sbin/ldconfig - -%postun -p /sbin/ldconfig - - -%files -%manifest %{name}.manifest -/usr/share/license/%{name} -%{_bindir}/lsdev -%{_bindir}/simple_sync diff --git a/example/simple_sync.c b/example/simple_sync.c deleted file mode 100644 index 2d60c65..0000000 --- a/example/simple_sync.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * simple_sync.c - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include - -#define BUF_LEN 8192 - -usb_host_device_h dev; - -static void print_devs(usb_host_device_h *devs, usb_host_context_h ctx) -{ - usb_host_device_h idev; - int i = 0, j = 0; - int path[8]; - int r; - int vid, pid, bus, addr; - int len; - - printf("Getting device list: \n"); - - while ((idev = devs[i++]) != NULL) { - usb_host_device_get_id_vendor(idev, &vid); - usb_host_device_get_id_product(idev, &pid); - usb_host_device_get_bus_number(idev, &bus); - usb_host_device_get_address(idev, &addr); - printf("%04x:%04x (bus %d, device %d)", vid, pid, bus, addr); - - r = usb_host_device_get_port_numbers(idev, path, 8, &len); - if (r < 0) - printf("cant get port numbers\n"); - else if (r > 0) { - printf(" path: %d", path[0]); - for (j = 1; j < len; j++) - printf(".%d", path[j]); - } - printf("\n"); - } -} - -static int connect_to_dev_interface(int vid, int pid, usb_host_context_h ctx) -{ - int r; - usb_host_interface_h iface; - usb_host_config_h cfg; - - r = usb_host_device_open_with_vid_pid(ctx, vid, pid, &dev); - if (r < 0) { - printf("cant get dev with vid pid\n"); - return -1; - } - - r = usb_host_get_active_config(dev, &cfg); - if (r < 0) { - printf("cant get active config\n"); - return -1; - } - - r = usb_host_config_get_interface(cfg, 0, &iface); - if (r < 0) { - printf("cant get interface 0\n"); - return r; - } - - printf("claiming iface\n"); - if (usb_host_claim_interface(iface, 1)) { - printf("can't claim interface: %s\n", - strerror(r)); - goto out; - } - - return 0; - -out: - usb_host_device_close(dev); - - usb_host_destroy(ctx); - return 1; -} - -int main(void) -{ - usb_host_context_h ctx; - usb_host_device_h *devs; - int r; - ssize_t cnt; - int vid,pid; - usb_host_interface_h interface; - usb_host_config_h cfg; - usb_host_endpoint_h in_ep, out_ep; - int n; - - r = usb_host_create(&ctx); - if (r < 0) - return r; - - r = usb_host_get_device_list(ctx, &devs, &cnt); - if (r < 0) - return r; - - printf("Getting dev list: \n"); - - print_devs(devs, ctx); - - printf("provide vid and pid of device which you want to operate on\n"); - printf("\n enter device vid and hit enter:"); - scanf ("%x",&vid); - printf("\n enter device pid and hit enter:"); - scanf ("%x",&pid); - - r = connect_to_dev_interface(vid, pid, ctx); - if (r < 0) { - printf("failure %s\n", strerror(r)); - return r; - } - - usb_host_device_get_config(dev, 0, &cfg); - usb_host_config_get_interface(cfg, 0, &interface); - usb_host_interface_get_endpoint(interface, 0, &in_ep); - usb_host_interface_get_endpoint(interface, 1, &out_ep); - - for(n = 0; n < 100; n++) { - static unsigned char buffer[BUF_LEN]; - int bytes; - usb_host_transfer(out_ep, buffer, BUF_LEN, - &bytes, 500); - usb_host_transfer(in_ep, buffer, BUF_LEN, - &bytes, 500); - } - printf("EXITING\n\n"); - - usb_host_release_interface(interface); - - usb_host_config_destroy(cfg); - usb_host_free_device_list(devs, 1); - - usb_host_device_close(dev); - usb_host_destroy(ctx); - - return 0; -} diff --git a/packaging/USD.manifest b/packaging/USD.manifest deleted file mode 100644 index 017d22d..0000000 --- a/packaging/USD.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/packaging/capi-system-usbhost.spec b/packaging/capi-system-usbhost.spec index 8fb82a9..ed54d65 100644 --- a/packaging/capi-system-usbhost.spec +++ b/packaging/capi-system-usbhost.spec @@ -1,6 +1,6 @@ Name: capi-system-usbhost Version: 0.0.1 -Release: 0 +Release: 1 License: Apache-2.0 Summary: RAW USB host API Group: Base/Device Management @@ -9,20 +9,9 @@ Source0: %{name}-%{version}.tar.gz Source1001: %{name}.manifest BuildRequires: pkg-config BuildRequires: cmake +BuildRequires: libattr-devel BuildRequires: pkgconfig(libusb-1.0) - -BuildRequires: zip -BuildRequires: pkgconfig(dlog) -BuildRequires: libattr-devel -BuildRequires: libcap-devel -%if "%{?_build_tests}" == "1" -BuildRequires: pkgconfig(cmocka) -%endif -BuildRequires: pkgconfig(libsmack) -BuildRequires: pkgconfig(libsystemd-daemon) -BuildRequires: pkgconfig(libsystemd-journal) -BuildRequires: pkgconfig(dbus-1) -%{?systemd_requires} +BuildRequires: pkgconfig(dlog) %description Usb-host is a librarary for raw communication with USB devices. @@ -36,35 +25,17 @@ Requires: %{name} = %{version}-%{release} Development package for capi-system-usbhost. Contains headers and binaries required for compilation of applications which use capi-system-usbhost. -%package target-tests -Summary: Test setup for target -Group: Development/Libraries -Requires: %{name} = %{version}-%{release} -Requires: gt -Requires: arm-odroidxu3-usb-host-tests-modules - -%description target-tests -Tests to be executed on target - %prep %setup -q cp %{SOURCE1001} . - %build -export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" -export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" -export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" export LDFLAGS="${LDFLAGS} -Wl,--rpath=%{_libdir}" %cmake . -DVERSION=%{version} \ -DCMAKE_BUILD_TYPE=%{?build_type:%build_type}%{!?build_type:RELEASE} \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DLIB_INSTALL_DIR=%{_libdir} \ - -DBUILD_TESTS=%{?_build_tests} \ - -DBUILD_TARGET_TESTS=1 \ - -DSYSTEMD_DIR=%{_unitdir} + -DCMAKE_VERBOSE_MAKEFILE=ON %__make %{?_smp_mflags} @@ -72,16 +43,8 @@ ctest -V %install rm -rf %{buildroot} -mkdir -p %{buildroot}%{_datadir}/license -mkdir -p %{buildroot}/usr/lib/tmpfiles.d -cp LICENSE %{buildroot}%{_datadir}/license/%{name} -mkdir -p %{buildroot}%{_sysconfdir}/security/ %make_install -mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants -mkdir -p %{buildroot}%{_unitdir}/sockets.target.wants - - %post -p /sbin/ldconfig %postun -p /sbin/ldconfig @@ -100,10 +63,9 @@ rm -rf %{buildroot} %files devel %manifest %{name}.manifest %defattr(-,root,root) +%license LICENSE %{_includedir}/usb_host.h %{_libdir}/lib%{name}.so %{_libdir}/pkgconfig/%{name}.pc -%{_datadir}/license/%{name} - %changelog diff --git a/packaging/libUSD-client.manifest b/packaging/libUSD-client.manifest deleted file mode 100644 index a76fdba..0000000 --- a/packaging/libUSD-client.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/pc/CMakeLists.txt b/pc/CMakeLists.txt deleted file mode 100644 index 356987a..0000000 --- a/pc/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# @file CMakeLists.txt -# @author Tomasz Swierczek (t.swierczek@samsung.com) -# - diff --git a/tests/libusb_wrap.c b/tests/libusb_wrap.c deleted file mode 100644 index d437753..0000000 --- a/tests/libusb_wrap.c +++ /dev/null @@ -1,421 +0,0 @@ -/* - * libusb_wrap.c - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int libusb_init(libusb_context **ctx) -{ - check_expected(ctx); - *ctx = mock_ptr_type(libusb_context *); - - return mock_type(int); -} - -libusb_device_handle * libusb_open_device_with_vid_pid(libusb_context *ctx, uint16_t vendor_id, uint16_t product_id) -{ - libusb_device_handle *handle; - - check_expected(ctx); - check_expected(vendor_id); - check_expected(product_id); - - return mock_ptr_type(libusb_device_handle *); -} - -void libusb_exit(libusb_context *ctx) -{ - check_expected(ctx); -} - -void libusb_set_debug(libusb_context *ctx, int level) -{ -} - -const struct libusb_version * libusb_get_version(void) -{ - return NULL; -} - -int libusb_has_capability(uint32_t capability) -{ - return 0; -} - -const char * libusb_error_name(int errcode) -{ - return NULL; -} - -ssize_t libusb_get_device_list(libusb_context *ctx, - libusb_device ***list) -{ - int n, i; - libusb_device **rlist; - - n = mock_type(int); - rlist = calloc(sizeof(libusb_device *), n); - for (i = 0; i < n; ++i) { - rlist[i] = mock_ptr_type(libusb_device *); - } - - *list = rlist; - return n; -} - -void libusb_free_device_list(libusb_device **list, - int unref_devices) -{ - free(list); -} - -libusb_device * libusb_ref_device(libusb_device *dev) -{ - check_expected(dev); - return dev; -} - -void libusb_unref_device(libusb_device *dev) -{ -} - -int libusb_get_configuration(libusb_device_handle *dev, - int *config) -{ - check_expected(dev); - *config = mock_type(int); - return mock_type(int); -} - -int libusb_get_device_descriptor(libusb_device *dev, - struct libusb_device_descriptor *desc) -{ - check_expected(dev); - check_expected(desc); - return mock_type(int); -} - -int libusb_get_active_config_descriptor(libusb_device *dev, - struct libusb_config_descriptor **config) -{ - return 0; -} - -static int deallocate_config_descriptor (struct libusb_config_descriptor *c, - int i, int j, int temp) -{ - while (i > 0) - { - --i; - while (j > 0) - { - --j; - free (c->interface[i].altsetting[j].endpoint); - } - j = temp; - free (c->interface[i].altsetting); - } - free (c->interface); - free (c); - - return LIBUSB_ERROR_NO_MEM; -} - -int libusb_get_config_descriptor(libusb_device *dev, - uint8_t config_index, struct libusb_config_descriptor **config) -{ - int i, j, k, temp; - - struct libusb_interface *iface; - struct libusb_interface_descriptor *desc; - struct libusb_endpoint_descriptor *ep; - - struct libusb_config_descriptor *c = malloc (sizeof (*c)); - if (!c) return LIBUSB_ERROR_NO_MEM; - - temp = mock_type(int); - - c->bNumInterfaces = temp; - c->interface = malloc(temp * sizeof(*iface)); - if (!c->interface) - { - free (c); - return LIBUSB_ERROR_NO_MEM; - } - - c->extra_length = 0; - for (i = 0; i < temp; ++i) - { - iface = c->interface + i; - iface->num_altsetting = temp; - iface->altsetting = malloc(temp * sizeof(*desc)); - if (!iface->altsetting) return deallocate_config_descriptor (c, i, j, temp); - for (j = 0; j < temp; ++j) - { - desc = iface->altsetting + j; - desc->bNumEndpoints = temp; - desc->endpoint = malloc(temp * sizeof(*ep)); - if (!desc->endpoint) return deallocate_config_descriptor (c, i, j, temp); - desc->extra_length = 0; - for (k = 0; k < temp; ++k) - { - ep = desc->endpoint + k; - ep->extra_length = 0; - } - } - j = 0; - } - - *config = c; - - return 0; -} - -int libusb_get_config_descriptor_by_value(libusb_device *dev, - uint8_t bConfigurationValue, struct libusb_config_descriptor **config) -{ - check_expected(dev); - *config = mock_ptr_type(struct libusb_config_descriptor *); - return mock_type(int); -} - -void libusb_free_config_descriptor( - struct libusb_config_descriptor *config) -{ -} - -uint8_t libusb_get_bus_number(libusb_device *dev) -{ - check_expected(dev); - return mock_type(uint8_t); -} - -uint8_t libusb_get_device_address(libusb_device *dev) -{ - check_expected(dev); - return mock_type(uint8_t); -} - -int libusb_get_port_numbers(libusb_device *dev, - uint8_t* port_numbers, int port_numbers_len) -{ - check_expected(dev); - *port_numbers = mock_type(uint8_t); - check_expected(port_numbers_len); - - return mock_type(int); -} - -int libusb_get_device_speed(libusb_device *dev) -{ - return 0; -} - -int libusb_get_max_packet_size(libusb_device *dev, - unsigned char endpoint) -{ - return 0; -} - -int libusb_get_max_iso_packet_size(libusb_device *dev, - unsigned char endpoint) -{ - check_expected(dev); - check_expected(endpoint); - return mock_type(int); -} - -int libusb_open(libusb_device *dev, libusb_device_handle **handle) -{ - check_expected(dev); - check_expected(handle); - *handle = mock_ptr_type(libusb_device_handle *); - return mock_type(int); -} - -void libusb_close(libusb_device_handle *dev_handle) -{ - check_expected (dev_handle); -} - -libusb_device * libusb_get_device(libusb_device_handle *dev_handle) -{ - return mock_ptr_type(libusb_device *); -} - -int libusb_set_configuration(libusb_device_handle *dev, - int configuration) -{ - check_expected(dev); - check_expected(configuration); - return mock_type(int); -} - -int libusb_claim_interface(libusb_device_handle *dev, - int interface_number) -{ - check_expected(dev); - check_expected(interface_number); - return mock_type(int); -} - -int libusb_release_interface(libusb_device_handle *dev, - int interface_number) -{ - check_expected(dev); - check_expected(interface_number); - return mock_type(int); -} - -int libusb_set_interface_alt_setting(libusb_device_handle *dev, - int interface_number, int alternate_setting) -{ - return 0; -} - -int libusb_clear_halt(libusb_device_handle *dev, - unsigned char endpoint) -{ - check_expected(dev); - check_expected(endpoint); - return mock_type(int); -} - -int libusb_reset_device(libusb_device_handle *dev) -{ - check_expected(dev); - return mock_type(int); -} - -int libusb_kernel_driver_active(libusb_device_handle *dev, - int interface_number) -{ - check_expected(dev); - check_expected(interface_number); - return mock_type(int); -} - -int libusb_detach_kernel_driver(libusb_device_handle *dev, - int interface_number) -{ - check_expected(dev); - check_expected(interface_number); - return mock_type(int); -} - -int libusb_attach_kernel_driver(libusb_device_handle *dev, - int interface_number) -{ - check_expected(dev); - check_expected(interface_number); - return mock_type(int); -} - -int libusb_control_transfer(libusb_device_handle *dev_handle, - uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, - unsigned char *data, uint16_t wLength, unsigned int timeout) -{ - check_expected(dev_handle); - check_expected(request_type); - check_expected(bRequest); - check_expected(wValue); - check_expected(wIndex); - check_expected(data); - check_expected(wLength); - check_expected(timeout); - - return mock_type(int); -} - -int libusb_bulk_transfer(libusb_device_handle *dev_handle, - uint8_t endpoint, unsigned char *data, int length, - int *transferred, unsigned int timeout) -{ - check_expected(dev_handle); - check_expected(endpoint); - check_expected(data); - check_expected(length); - check_expected(timeout); - - *transferred = mock_type(int); - - return mock_type(int); -} - -int libusb_interrupt_transfer(libusb_device_handle *dev_handle, - uint8_t endpoint, unsigned char *data, int length, - int *transferred, unsigned int timeout) -{ - check_expected(dev_handle); - check_expected(endpoint); - check_expected(data); - check_expected(length); - check_expected(timeout); - - *transferred = mock_type(int); - - return mock_type(int); -} - -int libusb_get_string_descriptor_ascii(libusb_device_handle *dev, - uint8_t desc_index, unsigned char *data, int length) -{ - check_expected(dev); - check_expected(desc_index); - check_expected(length); - - strcpy (data, mock_ptr_type(unsigned char *)); - return mock_type(int); -} - -struct libusb_transfer *libusb_alloc_transfer(int iso_packets) -{ - check_expected(iso_packets); - return mock_ptr_type(struct libusb_transfer *); -} - -void libusb_free_transfer(struct libusb_transfer *transfer) -{ - check_expected(transfer); -} - -int libusb_submit_transfer(struct libusb_transfer *transfer) -{ - check_expected(transfer); - return mock_type(int); -} - -int libusb_cancel_transfer(struct libusb_transfer *transfer) -{ - check_expected(transfer); - return mock_type(int); -} - -int libusb_handle_events_completed(libusb_context *ctx, int *completed) -{ - check_expected(ctx); - check_expected(completed); - return mock_type(int); -} diff --git a/tests/usb_host_test.c b/tests/usb_host_test.c deleted file mode 100644 index 39d906f..0000000 --- a/tests/usb_host_test.c +++ /dev/null @@ -1,736 +0,0 @@ -/* - * usb_host-test.c - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "usb_host.h" -#include "usb_host_internal.h" -#include -#include "uref.h" - -/* assertions and checks */ - -/** - * @brief Initialize library context and check results - */ -static int setup_usb_host_context(void **state) -{ - int ret; - usb_host_context_h ctx; - libusb_context *lusb_ctx; - - expect_any(libusb_init, ctx); - will_return(libusb_init, lusb_ctx); - will_return(libusb_init, LIBUSB_SUCCESS); - - ret = usb_host_create(&ctx); - - assert_return_code(ret, 0); - assert_ptr_equal(ctx->lusb_ctx, lusb_ctx); - - *state = (void *)ctx; - - return 0; -} - -static int teardown_usb_host_context(void **state) -{ - usb_host_context_h ctx; - - ctx = (usb_host_context_h )(*state); - expect_any(libusb_exit, ctx); - usb_host_destroy(ctx); - - return 0; -} - -static int setup_usb_host_device(void **state) -{ - usb_host_device_h dev; - - dev = malloc(sizeof(*dev)); - /* TODO fill this with something? */ - - dev->lusb_dev = rand(); - dev->lusb_dev_handle = rand(); - - *state = dev; - - return 0; -} - -/** - * @brief Just free the memory - */ -static int teardown_free(void **state) -{ - free(*state); - - return 0; -} - -/** - * @brief Test if initialization works fine - */ -static void test_init(void **state) -{ - usb_host_context_h ctx; - - ctx = (usb_host_context_h )(*state); - assert_non_null(ctx); -} - -static void test_open(void **state) -{ - usb_host_context_h ctx; - libusb_device_handle *lusb_handle; - struct usb_host_device_s device; - int ret; - - ctx = (usb_host_context_h )(*state); - assert_non_null(ctx); - - expect_value(libusb_open, dev, device.lusb_dev); - expect_any(libusb_open, handle); - will_return(libusb_open, lusb_handle); - will_return(libusb_open, 0); - - ret = usb_host_device_open(&device); - - assert_return_code(ret, 0); - assert_ptr_equal(device.lusb_dev_handle, lusb_handle); -} - -/* - * A pair of functions required for uref, - * to which usb_host_device_close relegates some work - * and expects to find inside a usb_host_device_s, - * so we cannot use a mock instance. - * - * No usb_host function returns a usb_host_device_s, - * so we need to manually instantiate one. - */ -static inline usb_host_device_h to_usb_host_device(struct uref *_uref) -{ - return container_of(_uref, struct usb_host_device_s, ref); -} - -static void free_device(struct uref *uref) -{ - usb_host_device_h dev = to_usb_host_device(uref); - - libusb_unref_device(dev->lusb_dev); - free(dev); -} - -static void test_close(void **state) -{ - usb_host_device_h handle; - - handle = (usb_host_device_h ) (*state); - assert_non_null(handle); - - handle->lusb_dev_handle = rand(); - - expect_value (libusb_close, dev_handle, handle->lusb_dev_handle); - usb_host_device_close (handle); -} - -static void test_get_devices(void **state) -{ - int n = 7, i, ret; - usb_host_context_h ctx; - usb_host_device_h *devs; - - libusb_device *lusb_devs[n]; - for (i = 0; i < n; ++i) - lusb_devs[i] = (libusb_device *) rand(); - - ctx = (usb_host_context_h )(*state); - assert_non_null(ctx); - - will_return(libusb_get_device_list, n); - for (i = 0; i < n; ++i) { - expect_any(libusb_ref_device, dev); - will_return(libusb_get_device_list, lusb_devs[i]); - - expect_value(libusb_get_device_descriptor, dev, lusb_devs[i]); - expect_any(libusb_get_device_descriptor, desc); - will_return(libusb_get_device_descriptor, 0); - } - - ret = usb_host_get_device_list(ctx, &devs); - - assert_int_equal(ret, n); - for (i = 0; i < n; ++i) - assert_ptr_equal(devs[i]->lusb_dev, lusb_devs[i]); - - usb_host_free_device_list(devs, 0); -} - -static void test_get_bus_number(void **state) -{ - usb_host_device_h device; - uint8_t expected, ret; - - expected = rand(); - device = (usb_host_device_h )(*state); - assert_non_null(device); - - expect_value(libusb_get_bus_number, dev, device->lusb_dev); - will_return(libusb_get_bus_number, expected); - - ret = usb_host_device_get_bus_number(device); - - assert_int_equal(ret, expected); -} - -static void test_get_address(void **state) -{ - usb_host_device_h device; - uint8_t expected, ret; - - expected = rand(); - device = (usb_host_device_h )(*state); - assert_non_null(device); - - expect_value(libusb_get_device_address, dev, device->lusb_dev); - will_return(libusb_get_device_address, expected); - - ret = usb_host_device_get_address(device); - - assert_int_equal(ret, expected); -} - -static void test_get_port_numbers(void **state) -{ - usb_host_device_h device; - uint8_t p_numbers[8]; - int ret, p_num_len; - - /* As per the USB 3.0 specs, the current maximum limit for the depth is 7 */ - p_num_len = 8; - device = (usb_host_device_h )(*state); - assert_non_null(device); - - expect_value(libusb_get_port_numbers, dev, device->lusb_dev); - expect_value(libusb_get_port_numbers, port_numbers_len, p_num_len); - will_return(libusb_get_port_numbers, p_num_len -1); - will_return(libusb_get_port_numbers, 0); - - ret = usb_host_device_get_port_numbers(device, p_numbers, p_num_len); - - assert_return_code(ret, 0); -} - -static void test_get_active_config(void **state) -{ - usb_host_device_h handle; - int expected, ret; - struct usb_host_config_s *conf; - struct libusb_config_descriptor desc; - - handle = (usb_host_device_h )(*state); - expected = rand(); - - desc.bNumInterfaces = 0; - desc.bConfigurationValue = expected; - - expect_value(libusb_get_configuration, dev, handle->lusb_dev_handle); - will_return(libusb_get_configuration, expected); - will_return(libusb_get_configuration, 0); - - expect_value(libusb_get_config_descriptor_by_value, dev, handle->lusb_dev); - will_return(libusb_get_config_descriptor_by_value, &desc); - will_return(libusb_get_config_descriptor_by_value, 0); - - ret = usb_host_get_active_config(handle, &conf); - - assert_return_code(ret, 0); -} - -static void test_open_device_vid_pid(void **state) -{ - usb_host_device_h handle; - usb_host_context_h ctx; - libusb_device_handle *lusb_dev_handle; - libusb_device *lusb_device; - uint16_t vid, pid; - - vid = (uint16_t)rand(); - pid = (uint16_t)rand(); - lusb_dev_handle = (libusb_device_handle *)rand(); - lusb_device = (libusb_device *)rand(); - - ctx = (usb_host_context_h )(*state); - assert_non_null(ctx); - - expect_value(libusb_open_device_with_vid_pid, ctx, ctx->lusb_ctx); - expect_value(libusb_open_device_with_vid_pid, vendor_id, vid); - expect_value(libusb_open_device_with_vid_pid, product_id, pid); - will_return(libusb_open_device_with_vid_pid, lusb_dev_handle); - will_return(libusb_get_device, lusb_device); - expect_any(libusb_ref_device, dev); - expect_value(libusb_get_device_descriptor, dev, lusb_device); - expect_any(libusb_get_device_descriptor, desc); - will_return(libusb_get_device_descriptor, 0); - - handle = usb_host_open_device_with_vid_pid(ctx, vid, pid); - - assert_non_null(handle); - assert_ptr_equal(handle->lusb_dev_handle, lusb_dev_handle); - assert_ptr_equal(handle->lusb_dev, lusb_device); - - expect_value (libusb_close, dev_handle, handle->lusb_dev_handle); - usb_host_device_close(handle); -} - -static void test_set_config(void **state) -{ - usb_host_device_h handle; - struct usb_host_config_s config; - uint8_t cfg_nmb; - int ret; - - cfg_nmb = rand(); - handle = (usb_host_device_h )(*state); - assert_non_null(handle); - - config.desc.bConfigurationValue = cfg_nmb; - config.dev = handle; - - expect_value(libusb_set_configuration, dev, handle->lusb_dev_handle); - expect_value(libusb_set_configuration, configuration, cfg_nmb); - will_return(libusb_set_configuration, 0); - - ret = usb_host_set_config(&config); - - assert_return_code(ret, 0); -} - -static void test_claim_interface_simple(void **state) -{ - usb_host_device_h handle; - struct usb_host_interface_s interface; - int ret; - - handle = (usb_host_device_h )(*state); - assert_non_null(handle); - - interface.num_altsettings = 1; - interface.altsettings = calloc(sizeof(*interface.altsettings), 1); - interface.altsetting = 0; - - interface.dev = handle; - interface.altsettings[0].desc.bInterfaceNumber = 0; - - expect_value(libusb_claim_interface, dev, handle->lusb_dev_handle); - expect_value(libusb_claim_interface, interface_number, interface.altsettings[0].desc.bInterfaceNumber); - will_return(libusb_claim_interface, 0); - - ret = usb_host_claim_interface(&interface, 0); - - assert_return_code(ret, 0); - - free(interface.altsettings); -} - -static void test_release_interface_simple(void **state) -{ - usb_host_device_h handle; - int interface_nmb, ret; - struct usb_host_interface_s interface; - - interface_nmb = rand() % MAX_NMB_OF_CONFIGS; - handle = (usb_host_device_h )(*state); - assert_non_null(handle); - handle->driver_detached[interface_nmb] = 0; - - interface.num_altsettings = 1; - interface.altsettings = calloc(sizeof(*interface.altsettings), 1); - interface.altsettings[0].desc.bInterfaceNumber = interface_nmb; - interface.altsetting = 0; - - interface.dev = handle; - - expect_value(libusb_release_interface, dev, handle->lusb_dev_handle); - expect_value(libusb_release_interface, interface_number, interface_nmb); - will_return(libusb_release_interface, 0); - - ret = usb_host_release_interface(&interface); - - assert_return_code(ret, 0); - - free(interface.altsettings); -} - -static void test_release_interface_attachment(void **state) -{ - usb_host_device_h handle; - int interface_nmb, ret; - struct usb_host_interface_s interface; - - interface_nmb = rand() % MAX_NMB_OF_CONFIGS; - handle = (usb_host_device_h )(*state); - assert_non_null(handle); - handle->driver_detached[interface_nmb] = 1; - - interface.num_altsettings = 1; - interface.altsettings = calloc(sizeof(*interface.altsettings), 1); - interface.altsettings[0].desc.bInterfaceNumber = interface_nmb; - interface.altsetting = 0; - - interface.dev = handle; - - expect_value(libusb_release_interface, dev, handle->lusb_dev_handle); - expect_value(libusb_release_interface, interface_number, interface_nmb); - will_return(libusb_release_interface, 0); - - expect_value(libusb_attach_kernel_driver, dev, handle->lusb_dev_handle); - expect_value(libusb_attach_kernel_driver, interface_number, interface_nmb); - will_return(libusb_attach_kernel_driver, 0); - - ret = usb_host_release_interface(&interface); - - assert_return_code(ret, 0); - assert_int_equal(0, handle->driver_detached[interface_nmb]); - - free(interface.altsettings); -} - -static void test_control_transfer(void **state) -{ - uint8_t request_type, bRequest; - uint16_t wValue, wIndex, wLength; - unsigned char *data; - unsigned int timeout; - int ret; - usb_host_device_h handle; - - handle = (usb_host_device_h )(*state); - assert_non_null(handle); - -#define EXPECT_VAL(val) expect_value(libusb_control_transfer, val, val); - EXPECT_VAL(request_type); - EXPECT_VAL(bRequest); - EXPECT_VAL(wValue); - EXPECT_VAL(wIndex); - EXPECT_VAL(data); - EXPECT_VAL(wLength); - EXPECT_VAL(timeout); -#undef EXPECT_VAL - expect_value(libusb_control_transfer, dev_handle, handle->lusb_dev_handle); - will_return(libusb_control_transfer, 0); - - ret = usb_host_control_transfer(handle, request_type, bRequest, wValue, - wIndex, data, wLength, timeout); - - assert_return_code(ret, 0); -} - -static void test_bulk_transfer_length_check(void **state) -{ - uint8_t endpoint; - unsigned char *data; - int length; - int transferred; - unsigned int timeout; - int ret; - usb_host_device_h handle; - struct usb_host_endpoint_s ep; - - length = rand(); - handle = (usb_host_device_h )(*state); - assert_non_null(handle); - - ep.desc.bmAttributes = USB_ENDPOINT_XFER_BULK; - ep.desc.bEndpointAddress = endpoint; - ep.dev = handle; - -#define EXPECT_VAL(val) expect_value(libusb_bulk_transfer, val, val); - EXPECT_VAL(endpoint); - EXPECT_VAL(data); - EXPECT_VAL(length); - EXPECT_VAL(timeout); -#undef EXPECT_VAL - expect_value(libusb_bulk_transfer, dev_handle, handle->lusb_dev_handle); - will_return(libusb_bulk_transfer, length); - will_return(libusb_bulk_transfer, 0); - - ret = usb_host_transfer(&ep, data, length, &transferred, timeout); - - assert_int_equal(transferred, length); - assert_return_code(ret, 0); -} - -static void test_bulk_transfer_simple(void **state) -{ - uint8_t endpoint; - unsigned char *data; - int length; - int transferred; - unsigned int timeout; - int ret; - usb_host_device_h handle; - struct usb_host_endpoint_s ep; - - handle = (usb_host_device_h )(*state); - assert_non_null(handle); - - ep.desc.bmAttributes = USB_ENDPOINT_XFER_BULK; - ep.desc.bEndpointAddress = endpoint; - ep.dev = handle; - -#define EXPECT_VAL(val) expect_value(libusb_bulk_transfer, val, val); - EXPECT_VAL(endpoint); - EXPECT_VAL(data); - EXPECT_VAL(length); - EXPECT_VAL(timeout); -#undef EXPECT_VAL - expect_value(libusb_bulk_transfer, dev_handle, handle->lusb_dev_handle); - will_return(libusb_bulk_transfer, rand()); - will_return(libusb_bulk_transfer, 0); - - ret = usb_host_transfer(&ep, data, length, &transferred, timeout); - - assert_return_code(ret, 0); -} - -static void test_interrupt_transfer_length_check(void **state) -{ - uint8_t endpoint; - unsigned char *data; - int length; - int transferred; - unsigned int timeout; - int ret; - usb_host_device_h handle; - struct usb_host_endpoint_s ep; - - length = rand(); - handle = (usb_host_device_h )(*state); - assert_non_null(handle); - - ep.desc.bmAttributes = USB_ENDPOINT_XFER_INT; - ep.desc.bEndpointAddress = endpoint; - ep.dev = handle; - -#define EXPECT_VAL(val) expect_value(libusb_interrupt_transfer, val, val); - EXPECT_VAL(endpoint); - EXPECT_VAL(data); - EXPECT_VAL(length); - EXPECT_VAL(timeout); -#undef EXPECT_VAL - expect_value(libusb_interrupt_transfer, dev_handle, handle->lusb_dev_handle); - will_return(libusb_interrupt_transfer, length); - will_return(libusb_interrupt_transfer, 0); - - ret = usb_host_transfer(&ep, data, length, &transferred, timeout); - - assert_int_equal(transferred, length); - assert_return_code(ret, 0); -} - -static void test_interrupt_transfer_simple(void **state) -{ - uint8_t endpoint; - unsigned char *data; - int length; - int transferred; - unsigned int timeout; - int ret; - usb_host_device_h handle; - struct usb_host_endpoint_s ep; - - handle = (usb_host_device_h )(*state); - assert_non_null(handle); - - ep.desc.bmAttributes = USB_ENDPOINT_XFER_INT; - ep.desc.bEndpointAddress = endpoint; - ep.dev = handle; - -#define EXPECT_VAL(val) expect_value(libusb_interrupt_transfer, val, val); - EXPECT_VAL(endpoint); - EXPECT_VAL(data); - EXPECT_VAL(length); - EXPECT_VAL(timeout); -#undef EXPECT_VAL - expect_value(libusb_interrupt_transfer, dev_handle, handle->lusb_dev_handle); - will_return(libusb_interrupt_transfer, rand()); - will_return(libusb_interrupt_transfer, 0); - - ret = usb_host_transfer(&ep, data, length, &transferred, timeout); - - assert_return_code(ret, 0); -} - -static void test_get_string_descriptor_ascii(void **state) -{ - usb_host_device_h handle; - uint8_t desc_index; - unsigned char data [16]; - int length, ret; - const char * testString = "TestString"; - - handle = (usb_host_device_h )(*state); - assert_non_null(handle); - - expect_value(libusb_get_string_descriptor_ascii, dev, handle->lusb_dev_handle); - expect_value(libusb_get_string_descriptor_ascii, desc_index, desc_index); - expect_value(libusb_get_string_descriptor_ascii, length, length); - will_return(libusb_get_string_descriptor_ascii, cast_ptr_to_largest_integral_type(testString)); - will_return(libusb_get_string_descriptor_ascii, 0); - - ret = usb_host_get_string_descriptor_ascii(handle, desc_index, length, data); - - assert_return_code(ret, 0); - assert_string_equal(data, testString); -} - -static void test_get_config(void **state) -{ - usb_host_config_h config; - usb_host_device_h dev; - uint8_t config_index; - int ret, interfaces; - - config_index = rand(); - interfaces = rand() % 6 + 1; // not too large, n^4 objects are created - dev = (usb_host_device_h )(*state); - assert_non_null(dev); - - will_return(libusb_get_config_descriptor, interfaces); - - ret = usb_host_device_get_config(dev, config_index, &config); - - assert_return_code(ret, 0); - - usb_host_free_config(config); -} - -/* Custom macro for defining test with given name and fixed teardown function */ -#define HUSB_TEST(func, setup, teardown) \ - cmocka_unit_test_setup_teardown(func, setup, teardown) -#define HUSB_TEST_CTX(func) \ - cmocka_unit_test_setup_teardown(func, setup_usb_host_context, teardown_usb_host_context) -#define HUSB_TEST_DEVICE(func) \ - cmocka_unit_test_setup_teardown(func, setup_usb_host_device, teardown_free) -#define HUSB_TEST_NOSETUP(func) \ - cmocka_unit_test(func) -#define HUSB_TEST_NO_TEARDOWN(func, setup) \ - cmocka_unit_test_setup (func, setup) - -static struct CMUnitTest tests[] = { - - /** - * @some_test - */ - /** - * @brief Check if library is initailized correctly - */ - HUSB_TEST_CTX(test_init), - /** - * @brief check if devices are opened correctly - */ - HUSB_TEST_CTX(test_open), - /** - * @brief Check if devices are closed correctly - */ - HUSB_TEST_DEVICE(test_close), // the tested function does the teardown - /** - * @brief check if list of devices is retrieved correctly - */ - HUSB_TEST_CTX(test_get_devices), - /** - * @brief Check if bus number is retrieved correctly - */ - HUSB_TEST_DEVICE(test_get_bus_number), - /** - * @brief check if address is retrieved correctly - */ - HUSB_TEST_DEVICE(test_get_address), - /** - * @brief check if port numbers are retrieved correctly - */ - HUSB_TEST_DEVICE(test_get_port_numbers), - /** - * @brief Check if active configuration is retrieved correctly - */ - HUSB_TEST_DEVICE(test_get_active_config), - /** - * @brief Check if device is opened correctly by usb_host_open_device_with_vid_pid() function - */ - HUSB_TEST_CTX(test_open_device_vid_pid), - /** - * @brief Check if configuration is set correctly - */ - HUSB_TEST_DEVICE(test_set_config), - /** - * @brief Check if interfaces are claimed correctly - */ - HUSB_TEST_DEVICE(test_claim_interface_simple), - /** - * @brief Check if control transfer works as exepected - */ - HUSB_TEST_DEVICE(test_control_transfer), - /** - * @brief Check if bulk transfer works as expected - */ - HUSB_TEST_DEVICE(test_bulk_transfer_simple), - /** - * @brief Check if bulk transfer fill length field with proper value - */ - HUSB_TEST_DEVICE(test_bulk_transfer_length_check), - /** - * @brief Check if interfaces are released correctly - */ - HUSB_TEST_DEVICE(test_release_interface_simple), - /** - * @brief Check if drivers are reattached afrer releasing interface - */ - HUSB_TEST_DEVICE(test_release_interface_attachment), - /** - * @brief Check if interrupt transfer works as expected - */ - HUSB_TEST_DEVICE(test_interrupt_transfer_simple), - /** - * @brief Check if interrupt transfer fill length field with proper value - */ - HUSB_TEST_DEVICE(test_interrupt_transfer_length_check), - /** - * @brief Check if string descriptor getter returns correct data - */ - HUSB_TEST_DEVICE(test_get_string_descriptor_ascii), - /** - * @brief Check if configuration object is retrieved correctly - */ - HUSB_TEST_DEVICE(test_get_config), -}; - - -int main(int argc, char **argv) -{ - srand(time(NULL)); - return cmocka_run_group_tests(tests, NULL, NULL); -} diff --git a/usb-security-daemon.conf b/usb-security-daemon.conf deleted file mode 100644 index 77b5a91..0000000 --- a/usb-security-daemon.conf +++ /dev/null @@ -1 +0,0 @@ -d /run/usb-security-daemon 1755 root root 10d