Skip to content

Commit

Permalink
return status from API call from RESTClient::send(); appropriately de…
Browse files Browse the repository at this point in the history
…ny a grant if supervisor is enabled and a permit call fails; fix issue with CMake not caching compiler information;
  • Loading branch information
gatekeep committed Mar 28, 2023
1 parent f36426a commit ab622ee
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 17 deletions.
20 changes: 10 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,15 @@ option(CROSS_COMPILE_ARM "Cross-compile for 32-bit ARM" off)
option(CROSS_COMPILE_AARCH64 "Cross-compile for 64-bit ARM" off)
option(CROSS_COMPILE_RPI_ARM "Cross-compile for (old RPi) 32-bit ARM" off)

set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
set(CMAKE_C_COMPILER gcc CACHE FILEPATH "CMAKE_C_COMPILER")
set(CMAKE_CXX_COMPILER g++ CACHE FILEPATH "CMAKE_CXX_COMPILER")
set(ARCH amd64)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE amd64)

message(CHECK_START "Cross compiling for 32-bit ARM")
if (CROSS_COMPILE_ARM)
set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc CACHE FILEPATH "CMAKE_C_COMPILER")
set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++ CACHE FILEPATH "CMAKE_CXX_COMPILER")
set(ARCH arm)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE arm)
message(CHECK_PASS "yes")
Expand All @@ -307,8 +307,8 @@ else ()
endif (CROSS_COMPILE_ARM)
message(CHECK_START "Cross compiling for 64-bit ARM")
if (CROSS_COMPILE_AARCH64)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc CACHE FILEPATH "CMAKE_C_COMPILER")
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++ CACHE FILEPATH "CMAKE_CXX_COMPILER")
set(ARCH arm64)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE arm64)
message(CHECK_PASS "yes")
Expand All @@ -332,11 +332,11 @@ if (CROSS_COMPILE_RPI_ARM)
GIT_REPOSITORY https://github.com/raspberrypi/tools.git
)
FetchContent_MakeAvailable(RPiTools)
set(CMAKE_C_COMPILER ${CMAKE_CURRENT_BINARY_DIR}/_deps/rpitools-src/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${CMAKE_CURRENT_BINARY_DIR}/_deps/rpitools-src/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++)
set(CMAKE_C_COMPILER ${CMAKE_CURRENT_BINARY_DIR}/_deps/rpitools-src/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc CACHE FILEPATH "CMAKE_C_COMPILER")
set(CMAKE_CXX_COMPILER ${CMAKE_CURRENT_BINARY_DIR}/_deps/rpitools-src/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ CACHE FILEPATH "CMAKE_CXX_COMPILER")
else()
set(CMAKE_C_COMPILER ${RPI_ARM_TOOLS}/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${RPI_ARM_TOOLS}/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++)
set(CMAKE_C_COMPILER ${RPI_ARM_TOOLS}/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc CACHE FILEPATH "CMAKE_C_COMPILER")
set(CMAKE_CXX_COMPILER ${RPI_ARM_TOOLS}/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ CACHE FILEPATH "CMAKE_CXX_COMPILER")
endif ()

set(ARCH armhf)
Expand Down
24 changes: 22 additions & 2 deletions src/dmr/packet/ControlSignaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,18 @@ bool ControlSignaling::writeRF_CSBK_Grant(uint32_t srcId, uint32_t dstId, uint8_
req["dstId"].set<uint32_t>(dstId);
req["slot"].set<uint8_t>(slot);

RESTClient::send(voiceChData.address(), voiceChData.port(), voiceChData.password(),
int ret = RESTClient::send(voiceChData.address(), voiceChData.port(), voiceChData.password(),
HTTP_PUT, PUT_PERMIT_TG, req, m_tscc->m_debug);
if (ret != network::rest::http::HTTPPayload::StatusType::OK) {
::LogError(LOG_RF, "DMR Slot %u, DT_CSBK, CSBKO_RAND (Random Access), failed to permit TG for use, chNo = %u, slot = %u", m_tscc->m_slotNo, chNo, slot);
m_tscc->m_affiliations->releaseGrant(dstId, false);
if (!net) {
writeRF_CSBK_ACK_RSP(srcId, TS_DENY_RSN_TGT_BUSY, (grp) ? 1U : 0U);
m_slot->m_rfState = RS_RF_REJECTED;
}

return false;
}
}
else {
::LogError(LOG_RF, "DMR Slot %u, DT_CSBK, CSBKO_RAND (Random Access), failed to permit TG for use, chNo = %u, slot = %u", m_tscc->m_slotNo, chNo, slot);
Expand Down Expand Up @@ -956,8 +966,18 @@ bool ControlSignaling::writeRF_CSBK_Grant(uint32_t srcId, uint32_t dstId, uint8_
req["dstId"].set<uint32_t>(dstId);
req["slot"].set<uint8_t>(slot);

RESTClient::send(voiceChData.address(), voiceChData.port(), voiceChData.password(),
int ret = RESTClient::send(voiceChData.address(), voiceChData.port(), voiceChData.password(),
HTTP_PUT, PUT_PERMIT_TG, req, m_tscc->m_debug);
if (ret != network::rest::http::HTTPPayload::StatusType::OK) {
::LogError(LOG_RF, "DMR Slot %u, DT_CSBK, CSBKO_RAND (Random Access), failed to permit TG for use, chNo = %u, slot = %u", m_tscc->m_slotNo, chNo, slot);
m_tscc->m_affiliations->releaseGrant(dstId, false);
if (!net) {
writeRF_CSBK_ACK_RSP(srcId, TS_DENY_RSN_TGT_BUSY, (grp) ? 1U : 0U);
m_slot->m_rfState = RS_RF_REJECTED;
}

return false;
}
}
else {
::LogError(LOG_RF, "DMR Slot %u, DT_CSBK, CSBKO_RAND (Random Access), failed to permit TG for use, chNo = %u, slot = %u", m_tscc->m_slotNo, chNo, slot);
Expand Down
12 changes: 11 additions & 1 deletion src/nxdn/packet/Trunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,18 @@ bool Trunk::writeRF_Message_Grant(uint32_t srcId, uint32_t dstId, uint8_t servic
req["state"].set<int>(state);
req["dstId"].set<uint32_t>(dstId);

RESTClient::send(voiceChData.address(), voiceChData.port(), voiceChData.password(),
int ret = RESTClient::send(voiceChData.address(), voiceChData.port(), voiceChData.password(),
HTTP_PUT, PUT_PERMIT_TG, req, m_nxdn->m_debug);
if (ret != network::rest::http::HTTPPayload::StatusType::OK) {
::LogError((net) ? LOG_NET : LOG_RF, "NXDN, " NXDN_RTCH_MSG_TYPE_VCALL_RESP ", failed to permit TG for use, chNo = %u", chNo);
m_nxdn->m_affiliations.releaseGrant(dstId, false);
if (!net) {
writeRF_Message_Deny(0U, srcId, NXDN_CAUSE_VD_QUE_GRP_BUSY, RTCH_MESSAGE_TYPE_VCALL);
m_nxdn->m_rfState = RS_RF_REJECTED;
}

return false;
}
}
else {
::LogError((net) ? LOG_NET : LOG_RF, "NXDN, " NXDN_RTCH_MSG_TYPE_VCALL_RESP ", failed to permit TG for use, chNo = %u", chNo);
Expand Down
26 changes: 23 additions & 3 deletions src/p25/packet/Trunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2245,8 +2245,18 @@ bool Trunk::writeRF_TSDU_Grant(uint32_t srcId, uint32_t dstId, uint8_t serviceOp
req["state"].set<int>(state);
req["dstId"].set<uint32_t>(dstId);

RESTClient::send(voiceChData.address(), voiceChData.port(), voiceChData.password(),
int ret = RESTClient::send(voiceChData.address(), voiceChData.port(), voiceChData.password(),
HTTP_PUT, PUT_PERMIT_TG, req, m_p25->m_debug);
if (ret != network::rest::http::HTTPPayload::StatusType::OK) {
::LogError((net) ? LOG_NET : LOG_RF, P25_TSDU_STR ", TSBK_IOSP_GRP_VCH (Group Voice Channel Grant), failed to permit TG for use, chNo = %u", chNo);
m_p25->m_affiliations.releaseGrant(dstId, false);
if (!net) {
writeRF_TSDU_Deny(srcId, dstId, P25_DENY_RSN_PTT_BONK, (grp) ? TSBK_IOSP_GRP_VCH : TSBK_IOSP_UU_VCH);
m_p25->m_rfState = RS_RF_REJECTED;
}

return false;
}
}
else {
::LogError((net) ? LOG_NET : LOG_RF, P25_TSDU_STR ", TSBK_IOSP_GRP_VCH (Group Voice Channel Grant), failed to permit TG for use, chNo = %u", chNo);
Expand Down Expand Up @@ -2285,11 +2295,21 @@ bool Trunk::writeRF_TSDU_Grant(uint32_t srcId, uint32_t dstId, uint8_t serviceOp
req["state"].set<int>(state);
req["dstId"].set<uint32_t>(dstId);

RESTClient::send(voiceChData.address(), voiceChData.port(), voiceChData.password(),
int ret = RESTClient::send(voiceChData.address(), voiceChData.port(), voiceChData.password(),
HTTP_PUT, PUT_PERMIT_TG, req, m_p25->m_debug);
if (ret != network::rest::http::HTTPPayload::StatusType::OK) {
::LogError((net) ? LOG_NET : LOG_RF, P25_TSDU_STR ", TSBK_IOSP_UU_VCH (Unit-to-Unit Voice Channel Grant), failed to permit TG for use, chNo = %u", chNo);
m_p25->m_affiliations.releaseGrant(dstId, false);
if (!net) {
writeRF_TSDU_Deny(srcId, dstId, P25_DENY_RSN_PTT_BONK, (grp) ? TSBK_IOSP_GRP_VCH : TSBK_IOSP_UU_VCH);
m_p25->m_rfState = RS_RF_REJECTED;
}

return false;
}
}
else {
::LogError((net) ? LOG_NET : LOG_RF, P25_TSDU_STR ", TSBK_IOSP_GRP_VCH (Group Voice Channel Grant), failed to permit TG for use, chNo = %u", chNo);
::LogError((net) ? LOG_NET : LOG_RF, P25_TSDU_STR ", TSBK_IOSP_UU_VCH (Unit-to-Unit Voice Channel Grant), failed to permit TG for use, chNo = %u", chNo);
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/remote/RESTClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ int RESTClient::send(const std::string& address, uint32_t port, const std::strin
assert(port > 0U);
assert(password.empty());

int ret = EXIT_SUCCESS;
m_debug = debug;

typedef network::rest::BasicRequestDispatcher<network::rest::http::HTTPPayload, network::rest::http::HTTPPayload> RESTDispatcherType;
Expand Down Expand Up @@ -254,6 +255,12 @@ int RESTClient::send(const std::string& address, uint32_t port, const std::strin
return ERRNO_API_CALL_TIMEOUT;
}

rsp = json::object();
if (!parseResponseBody(m_response, rsp)) {
return ERRNO_BAD_API_RESPONSE;
}

ret = rsp["status"].get<int>();
if (m_console) {
fprintf(stdout, "%s\r\n", m_response.content.c_str());
}
Expand All @@ -273,7 +280,7 @@ int RESTClient::send(const std::string& address, uint32_t port, const std::strin
return ERRNO_INTERNAL_ERROR;
}

return EXIT_SUCCESS;
return ret;
}

// ---------------------------------------------------------------------------
Expand Down

0 comments on commit ab622ee

Please sign in to comment.