forked from usb-tools/USBProxy-legacy
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: aws greengrass integration (#22)
- Loading branch information
1 parent
4129b1f
commit 273aae5
Showing
13 changed files
with
162 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ on: | |
paths: | ||
- 'aptly/Dockerfile' | ||
branches: master | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build-aptly: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,5 @@ obj-x86_64-linux-gnu | |
# nesto-specific | ||
src/build | ||
cppzmq | ||
usb-mitm.tar | ||
usb-mitm.tar | ||
src/lib/usbproxy.pc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
git clone https://github.com/aws/aws-greengrass-core-sdk-c.git /tmp/aws-sdk | ||
(cd /tmp/aws-sdk/aws-greengrass-core-sdk-c && mkdir -p build && cd build && cmake .. && cmake --build . && sudo make install) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# minimal CMakeLists.txt for the AWS Greengrass SDK for C | ||
cmake_minimum_required(VERSION 2.8) | ||
set(TOOL usb-mitm-gg) | ||
LIST(APPEND TOOLS_LINK_LIBS USBProxy -pthread zmq aws-greengrass-core-sdk-c) | ||
|
||
find_package(aws-greengrass-core-sdk-c REQUIRED) | ||
|
||
include_directories(${libusbproxy_SOURCE_DIR}) | ||
add_executable(${TOOL} main.cpp) | ||
target_link_libraries(${TOOL} ${TOOLS_LINK_LIBS}) | ||
target_compile_options(${TOOL} PRIVATE -Werror -Wall -Wextra -pedantic) | ||
|
||
install(TARGETS ${TOOL} RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#include <unistd.h> | ||
#include "greengrasssdk.h" | ||
|
||
#include "Manager.h" | ||
#include "ConfigParser.h" | ||
#include <signal.h> | ||
#include <zmq.hpp> | ||
|
||
Manager* manager; | ||
zmq::context_t *ctx = new zmq::context_t(); | ||
zmq::socket_t *frontend = new zmq::socket_t(*ctx, zmq::socket_type::xsub); | ||
zmq::socket_t *backend = new zmq::socket_t(*ctx, zmq::socket_type::xpub); | ||
|
||
void run_proxy(zmq::socket_t *frontend, zmq::socket_t *backend) { | ||
|
||
// proxy until context is destroyed, see: http://api.zeromq.org/3-2:zmq-proxy | ||
zmq::proxy(*frontend, *backend); | ||
} | ||
|
||
void handle_signal(int signum) | ||
{ | ||
struct sigaction action; | ||
switch (signum) { | ||
case SIGTERM: | ||
case SIGINT: | ||
if(signum == SIGTERM) | ||
fprintf(stderr, "Received SIGTERM, stopping relaying...\n"); | ||
else | ||
fprintf(stderr, "Received SIGINT, stopping relaying...\n"); | ||
if (manager) {manager->stop_relaying();} | ||
fprintf(stderr, "Exiting\n"); | ||
memset(&action, 0, sizeof(struct sigaction)); | ||
action.sa_handler = SIG_DFL; | ||
sigaction(SIGINT, &action, NULL); | ||
sigaction(SIGTERM, &action, NULL); | ||
break; | ||
case SIGHUP: | ||
fprintf(stderr, "Received SIGHUP, restarting relaying...\n"); | ||
if (manager) {manager->stop_relaying();} | ||
if (manager) {manager->start_control_relaying();} | ||
break; | ||
} | ||
} | ||
|
||
void handler(const gg_lambda_context *cxt) { | ||
(void)cxt; | ||
return; | ||
} | ||
|
||
int main() { | ||
gg_error err = GGE_SUCCESS; | ||
|
||
err = gg_global_init(0); | ||
if(err) { | ||
gg_log(GG_LOG_ERROR, "gg_global_init failed %d", err); | ||
return -1; | ||
} | ||
|
||
gg_runtime_start(handler, GG_RT_OPT_ASYNC); | ||
|
||
struct sigaction action; | ||
memset(&action, 0, sizeof(struct sigaction)); | ||
action.sa_handler = handle_signal; | ||
sigaction(SIGTERM, &action, NULL); | ||
sigaction(SIGHUP, &action, NULL); | ||
sigaction(SIGINT, &action, NULL); | ||
|
||
ConfigParser *cfg = new ConfigParser(); | ||
cfg->set("vendorId", "045e"); | ||
//cfg->set("productId", ""); | ||
cfg->set("DeviceProxy", "DeviceProxy_LibUSB"); | ||
cfg->set("HostProxy", "HostProxy_GadgetFS"); | ||
cfg->add_to_vector("Plugins", "PacketFilter_ZeroMQ"); | ||
|
||
|
||
(*frontend).bind("tcp://127.0.0.1:9999"); | ||
(*backend).bind("tcp://127.0.0.1:5678"); | ||
std::thread zmq_proxy = std::thread(run_proxy, std::ref(frontend), std::ref(backend)); | ||
|
||
int status; | ||
do { | ||
manager=new Manager(false); | ||
manager->load_plugins(cfg); | ||
cfg->print_config(); | ||
|
||
manager->start_control_relaying(); | ||
while ( ( status = manager->get_status()) == USBM_RELAYING) { | ||
std::this_thread::sleep_for(std::chrono::milliseconds(10)); | ||
} | ||
|
||
frontend->close(); | ||
backend->close(); | ||
zmq_proxy.join(); | ||
ctx->close(); | ||
manager->stop_relaying(); | ||
manager->cleanup(); | ||
delete(frontend); | ||
delete(backend); | ||
delete(manager); | ||
delete(ctx); | ||
} while ( status == USBM_RESET); | ||
|
||
return -1; | ||
} |