diff --git a/Build.md b/Build.md new file mode 100644 index 0000000..175ed72 --- /dev/null +++ b/Build.md @@ -0,0 +1,100 @@ +# Remote Provisioning Client (RPC) + +RPC is an application which enables remote capabilities for AMT, such as as device activation. To accomplish this, RPC communicates with the RPS (Remote Provisioning Server). + +The steps below assume the following directory structure where **rpc** is the clone of this repository, **vcpkg** is a clone of the VCPKG tool source and **build** is the RPC build directory. Both vcpkg and build directories will be created in later steps. + +``` +\rpc + |__vcpkg + |__build +``` + +# Linux + +Steps below are for Ubuntu 18.04 and 20.04. + +## Dependencies + +``` +sudo apt install git cmake build-essential libboost-system-dev libboost-thread-dev libboost-random-dev libboost-regex-dev libboost-filesystem-dev libssl-dev zlib1g-dev +``` + +## Build C++ REST SDK + +Open a Terminal window. + +``` +git clone https://github.com/microsoft/vcpkg.git +cd vcpkg +./bootstrap-vcpkg.bat +./vcpkg install cpprestsdk[websockets] +``` + +## Build RPC + +Open a Terminal window. + +``` +mkdir build +cd build +cmake -DCMAKE_TOOLCHAIN_FILE=/rpc/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release .. +cmake --build . +``` + +To build debug: +``` +cmake -DCMAKE_TOOLCHAIN_FILE=/rpc/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Debug .. +cmake --build . +``` + +## Run RPC + +Open a Terminal window. + +``` +cd build +sudo ./rpc --url wss://localhost:8080 --cmd "-t activate --profile profile1" +``` + +Use --help for more options. + +# Windows + +Steps below are for Windows 10 and Visual Studio 2019 Professional. + +## Build C++ REST SDK + +Open an x64 Native Tools Command Prompt for Visual Studio 2019. + +``` +git clone https://github.com/microsoft/vcpkg.git +cd vcpkg +bootstrap-vcpkg.bat +vcpkg install cpprestsdk[websockets]:x64-windows-static +``` + +## Build RPC +Open an x64 Native Tools Command Prompt for Visual Studio 2019. +``` +mkdir build +cd build +cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=/rpc/vcpkg/scripts/buildsystems/vcpkg.cmake .. +cmake --build . --config Release +``` + +To build debug: +``` +cmake --build . --config Debug +``` + +## Run RPC + +Open a Command Prompt as Administrator. + +``` +cd build\Release +rpc.exe --url wss://localhost:8080 --cmd "-t activate --profile profile1" +``` + +Use --help for more options. \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index d929b2b..f1a4c81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,14 +5,10 @@ project (rpc VERSION 1.0.0) set (CMAKE_CXX_STANDARD 11) # RPC version info -configure_file(version.h.in - version.h) +configure_file(version.h.in version.h) include_directories(${PROJECT_BINARY_DIR}) -# TODO: figure out how to read the LMS version from repo like the main lms CMakeLists.txt -set (LMS_VERSION_STRING 1932.0.0.0) - -# Compiler settings [Obtained from CmakeLists.txt for lms] +# Common compiler settings string(APPEND CMAKE_CXX_FLAGS_DEBUG " -DDEBUG -D_DEBUG") string(APPEND CMAKE_C_FLAGS_DEBUG " -DDEBUG -D_DEBUG") @@ -31,7 +27,6 @@ if (UNIX) else (UNIX) add_definitions (/GS /sdl) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NXCompat /DynamicBase") - #add_definitions (/D UNICODE /D _UNICODE) add_definitions (/D UNICODE /D _UNICODE /D_NO_ASYNCRTIMP /D_ASYNCRT_EXPORT /D_NO_PPLXIMP /DWIN32 /DMBCS /D_USRDLL /DCPPREST_EXCLUDE_COMPRESSION /D_WINSOCK_DEPRECATED_NO_WARNINGS) add_compile_options ($<$:/O2>) add_compile_options (/MT$<$:d>) @@ -42,49 +37,10 @@ endif (UNIX) # Add MicroLMS directly to our build. This adds # the following targets: MicroLMS add_subdirectory(MicroLMS) -#add_dependencies(rpc MicroLMS) - -if (UNIX) - -# Find threads [unix it pthreads] -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads REQUIRED) - -# Find Boost -set(Boost_USE_STATIC_LIBS ON) -find_package(Boost COMPONENTS system REQUIRED) - -# Find OpenSSL -find_package(OpenSSL) - -# Find ZLIB -find_package(ZLIB) - -# Download and build CppRestSDK, If GIT_TAG is changed then need to delete cpprestsdk-prefix because UPDATE_COMMAND is set to "" -include(ExternalProject) -ExternalProject_Add(cpprestsdk - GIT_REPOSITORY https://github.com/Microsoft/cpprestsdk.git - GIT_TAG v2.10.16 - CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=0 -DBUILD_SAMPLES=OFF -DBUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=/../../install - TEST_COMMAND "" - UPDATE_COMMAND "" -) -ExternalProject_Get_Property(cpprestsdk SOURCE_DIR) -set(CPPRESTSDK_LIBARIES ${SOURCE_DIR}/../../install/lib/) -set(CPPRESTSDK_INCLUDE_DIR ${SOURCE_DIR}/../../install/include/) - -add_library(cpprest INTERFACE) -target_link_libraries(cpprest INTERFACE ${CPPRESTSDK_LIBARIES}/libcpprest.a OpenSSL::SSL OpenSSL::Crypto ${Boost_LIBRARIES} Threads::Threads ZLIB::ZLIB) -target_include_directories(cpprest INTERFACE ${CPPRESTSDK_INCLUDE_DIR}) - -else (UNIX) # CppRestSDK find_package(cpprestsdk CONFIG REQUIRED) -endif (UNIX) - # ccu-poc add_executable (rpc info.h @@ -111,19 +67,20 @@ target_include_directories(rpc PUBLIC "MicroLMS/heci" ) -if (UNIX) +add_dependencies(rpc MicroLMS) -add_dependencies(rpc cpprestsdk) +if (UNIX) target_link_libraries (rpc PRIVATE MicroLMS - cpprest + cpprestsdk::cpprest + cpprestsdk::cpprestsdk_zlib_internal + cpprestsdk::cpprestsdk_boost_internal + cpprestsdk::cpprestsdk_openssl_internal ) else (UNIX) -add_dependencies(rpc MicroLMS ) - target_link_libraries (rpc PRIVATE MicroLMS cpprestsdk::cpprest diff --git a/CentOS7.md b/CentOS7.md new file mode 100644 index 0000000..1657ab1 --- /dev/null +++ b/CentOS7.md @@ -0,0 +1,82 @@ +# Remote Provisioning Client (RPC) + +RPC is an application which enables remote capabilities for AMT, such as as device activation. To accomplish this, RPC communicates with the RPS (Remote Provisioning Server). + +The steps below assume the following directory structure where **rpc** is the clone of this repository, **vcpkg** is a clone of the VCPKG tool source and **build** is the RPC build directory. Both vcpkg and build directories will be created in later steps. + +``` +\rpc + |__vcpkg + |__build +``` + +# Linux + +Steps below are for CentOS7. + +**The "export PATH=..." for CMake and "scl enable devtoolset-7 bash" must be executed in in the Terminal you are building from; i.e. these are temporary changes which only affect the current Terminal session.** + +## Dependencies + +### CMake +Download cmake-3.10.2-Linux-x86_64.sh from https://github.com/Kitware/CMake/releases/tag/v3.10.2. + +``` +./cmake-3.10.2-Linux-x86_64.sh +export PATH=/home/user/Downloads/cmake-3.10.2-Linux-x86_64/bin:$PATH +``` + +### GCC +Update GCC toolchain. + +``` +sudo yum install centos-release-scl +sudo yum install devtoolset-7 +scl enable devtoolset-7 bash +``` + +### Git +Update Git source control. +``` +rpm -U http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm \ + && yum install -y git +``` + +## Build C++ REST SDK + +Using a Terminal window with the PATH and devtoolset enabled per the Dependencies. + +``` +git clone https://github.com/microsoft/vcpkg.git +cd vcpkg +./bootstrap-vcpkg.bat +./vcpkg install cpprestsdk[websockets] +``` + +## Build RPC + +Using a Terminal window with the PATH and devtoolset enabled per the Dependencies. + +``` +mkdir build +cd build +cmake -DCMAKE_TOOLCHAIN_FILE=/rpc/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release .. +cmake --build . +``` + +To build debug: +``` +cmake -DCMAKE_TOOLCHAIN_FILE=/rpc/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Debug .. +cmake --build . +``` + +## Run RPC + +Open a Terminal window. + +``` +cd build +sudo ./rpc --url wss://localhost:8080 --cmd "-t activate --profile profile1" +``` + +Use --help for more options. diff --git a/MicroLMS/CMakeLists.txt b/MicroLMS/CMakeLists.txt index 263960c..4d93cc2 100644 --- a/MicroLMS/CMakeLists.txt +++ b/MicroLMS/CMakeLists.txt @@ -37,6 +37,10 @@ if (${BUILD_LIBRARY}) add_definitions(-D BUILD_LIBRARY) endif (${BUILD_LIBRARY}) +if (${NO_SELECT}) +add_definitions(-D NO_SELECT) +endif (${NO_SELECT}) + add_definitions( -D_POSIX ) else (UNIX) @@ -183,16 +187,5 @@ target_link_libraries ( endif (BUILD_LIBRARY) - - - - - - - - - - - endif (UNIX) diff --git a/MicroLMS/heci/HECILinux.c b/MicroLMS/heci/HECILinux.c index 4b97e32..08e6e2b 100644 --- a/MicroLMS/heci/HECILinux.c +++ b/MicroLMS/heci/HECILinux.c @@ -105,13 +105,17 @@ static ssize_t mei_recv_msg(struct mei *me, unsigned char *buffer, ssize_t len, static ssize_t mei_send_msg(struct mei *me, const unsigned char *buffer, ssize_t len, unsigned long timeout) { +#ifndef NO_SELECT struct timeval tv; +#endif ssize_t written; ssize_t rc; fd_set set; +#ifndef NO_SELECT tv.tv_sec = timeout / 1000; tv.tv_usec = (timeout % 1000) * 1000000; +#endif mei_msg(me, "call write length = %zd, cmd=%d\n", len, (int)buffer[0]); @@ -123,7 +127,7 @@ static ssize_t mei_send_msg(struct mei *me, const unsigned char *buffer, ssize_t mei_err(me, "write failed with status %zd %s\n", written, strerror(errno)); goto out; } - +#ifndef NO_SELECT FD_ZERO(&set); FD_SET(me->fd, &set); rc = select(me->fd + 1 , NULL, &set, NULL, &tv); @@ -136,7 +140,7 @@ static ssize_t mei_send_msg(struct mei *me, const unsigned char *buffer, ssize_t mei_err(me, "write failed on select with status %zd\n", rc); goto out; } - +#endif rc = written; out: sem_post(&(me->Lock));