Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unused functions from evsev2g #1012

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions modules/EvseV2G/connection/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,6 @@ void connection_teardown(struct v2g_connection* conn) {
/* init charging session */
v2g_ctx_init_charging_session(conn->ctx, true);

/* stop timer */
stop_timer(&conn->ctx->com_setup_timeout, nullptr, conn->ctx);

/* print dlink status */
switch (conn->dlink_action) {
case MQTT_DLINK_ACTION_ERROR:
Expand Down Expand Up @@ -861,8 +858,7 @@ static void* connection_handle_tls(void* data) {

if (rv != 0) {
if (((rv != MBEDTLS_ERR_SSL_WANT_READ) && (rv != MBEDTLS_ERR_SSL_WANT_WRITE) &&
(rv != MBEDTLS_ERR_SSL_TIMEOUT)) ||
(NULL == conn->ctx->com_setup_timeout)) {
(rv != MBEDTLS_ERR_SSL_TIMEOUT)) {
dlog(DLOG_LEVEL_ERROR, "mbedtls_ssl_handshake returned -0x%04x", -rv);
goto thread_exit;
}
Expand Down
4 changes: 0 additions & 4 deletions modules/EvseV2G/din_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,6 @@ static enum v2g_event handle_din_session_setup(struct v2g_connection* conn) {
1]; /* format: (%02x:) * n - 1x ':' + 1x NUL */
int idx;

/* un-arm a potentially communication setup timeout */
/* dis-arm our communication setup timeout, for this we must hold the MQTT lock */
stop_timer(&conn->ctx->com_setup_timeout, "session_setup: V2G_COMMUNICATION_SETUP_TIMER", conn->ctx);

/* format EVCC ID */
for (idx = 0; idx < req->EVCCID.bytesLen; idx++) {
sprintf(&buffer[idx * 3], "%02" PRIX8 ":", req->EVCCID.bytes[idx]);
Expand Down
2 changes: 0 additions & 2 deletions modules/EvseV2G/iso_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,6 @@ static enum v2g_event handle_iso_session_setup(struct v2g_connection* conn) {

dlog(DLOG_LEVEL_INFO, "SessionSetupReq.EVCCID: %s", std::string(buffer).size() ? buffer : "(zero length provided)");

/* un-arm a potentially communication setup timeout */
stop_timer(&conn->ctx->com_setup_timeout, "session_setup: V2G_COMMUNICATION_SETUP_TIMER", conn->ctx);

/* [V2G2-756]: If the SECC receives a SessionSetupReq including a SessionID value which is not
* equal to zero (0) and not equal to the SessionID value stored from the preceding V2G
Expand Down
169 changes: 0 additions & 169 deletions modules/EvseV2G/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ int generate_random_data(void* dest, size_t dest_len) {
return 0;
}

unsigned int generate_srand_seed(void) {
unsigned int s;

if (generate_random_data(&s, sizeof(s)) == -1)
return 42; /* just to _not_ use 1 which is the default value when srand is not used at all */

return s;
}

const char* choose_first_ipv6_interface() {
struct ifaddrs *ifaddr, *ifa;
char buffer[INET6_ADDRSTRLEN];
Expand Down Expand Up @@ -174,40 +165,10 @@ void timespec_add_ms(struct timespec* ts, long long msec) {
set_normalized_timespec(ts, ts->tv_sec + sec, ts->tv_nsec + (msec - sec * 1000) * 1000 * 1000);
}

/*
* lhs < rhs: return < 0
* lhs == rhs: return 0
* lhs > rhs: return > 0
*/
int timespec_compare(const struct timespec* lhs, const struct timespec* rhs) {
if (lhs->tv_sec < rhs->tv_sec)
return -1;
if (lhs->tv_sec > rhs->tv_sec)
return 1;
return lhs->tv_nsec - rhs->tv_nsec;
}

long long timespec_to_ms(struct timespec ts) {
return ((long long)ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
}

long long timespec_to_us(struct timespec ts) {
return ((long long)ts.tv_sec * 1000000) + (ts.tv_nsec / 1000);
}

int msleep(int ms) {
struct timespec req, rem;

req.tv_sec = ms / 1000;
req.tv_nsec = (ms % 1000) * (1000 * 1000); /* x ms */

while ((nanosleep(&req, &rem) == (-1)) && (errno == EINTR)) {
req = rem;
}

return 0;
}

long long int getmonotonictime() {
struct timespec time;
clock_gettime(CLOCK_MONOTONIC, &time);
Expand All @@ -218,136 +179,6 @@ double calc_physical_value(const int16_t& value, const int8_t& multiplier) {
return static_cast<double>(value * pow(10.0, multiplier));
}

bool range_check_int32(int32_t min, int32_t max, int32_t value) {
return ((value < min) || (value > max)) ? false : true;
}

bool range_check_int64(int64_t min, int64_t max, int64_t value) {
return ((value < min) || (value > max)) ? false : true;
}

void round_down(const char* buffer, size_t len) {
char* p;

p = (char*)strchr(buffer, '.');

if (!p)
return;

if (p - buffer > len - 2)
return;

if (*(p + 1) == '\0')
return;

*(p + 2) = '\0';
}

bool get_dir_filename(char* file_name, uint8_t file_name_len, const char* path, const char* file_name_identifier) {

file_name[0] = '\0';

if (path == NULL) {
dlog(DLOG_LEVEL_ERROR, "Invalid file path");
return false;
}
DIR* d = opendir(path); // open the path

if (d == NULL) {
dlog(DLOG_LEVEL_ERROR, "Unable to open file path %s", path);
return false;
}
struct dirent* dir; // for the directory entries
uint8_t file_name_identifier_len = std::string(file_name_identifier).size();
while ((dir = readdir(d)) != NULL) {
if (dir->d_type != DT_DIR) {
/* if the type is not directory*/
if ((std::string(dir->d_name).size() > (file_name_identifier_len)) && /* Plus one for the numbering */
(strncmp(file_name_identifier, dir->d_name, file_name_identifier_len) == 0) &&
(file_name_len > std::string(dir->d_name).size())) {
strncpy(file_name, dir->d_name, std::string(dir->d_name).size() + 1);
break;
}
}
}

closedir(d);

return (file_name[0] != '\0');
}

uint8_t get_dir_numbered_file_names(char file_names[MAX_PKI_CA_LENGTH][MAX_FILE_NAME_LENGTH], const char* path,
const char* prefix, const char* suffix, const uint8_t offset,
const uint8_t max_idx) {
if (path == NULL) {
dlog(DLOG_LEVEL_ERROR, "Invalid file path");
return 0;
}

DIR* d = opendir(path); // open the path

if (d == NULL) {
dlog(DLOG_LEVEL_ERROR, "Unable to open file path %s", path);
return 0;
}
struct dirent* dir; // for the directory entries
uint8_t num_of_files = 0;
uint8_t prefix_len = std::string(prefix).size();
uint8_t suffix_len = std::string(suffix).size();
uint8_t min_idx = max_idx; // helper value to re-sort array

while (((dir = readdir(d)) != NULL) && (num_of_files != (max_idx - offset))) {
if (dir->d_type != DT_DIR) {
/* if the type is not directory*/
if ((std::string(dir->d_name).size() > (prefix_len + suffix_len + 1)) && /* Plus one for the numbering */
(0 == strncmp(prefix, dir->d_name, prefix_len))) {
for (uint8_t idx = offset; idx < max_idx; idx++) {
/* Iterated over the number prefix */
if ((dir->d_name[prefix_len] == ('0' + idx)) &&
(strncmp(suffix, &dir->d_name[prefix_len + 1], suffix_len) == 0)) {
if (MAX_FILE_NAME_LENGTH >= std::string(dir->d_name).size()) {
strcpy(file_names[idx], dir->d_name);
// dlog(DLOG_LEVEL_ERROR,"Cert-file found: %s", &AFileNames[idx]);
num_of_files++;
min_idx = std::min(min_idx, idx);
} else {
dlog(DLOG_LEVEL_ERROR, "Max. file-name size exceeded. Only %i characters supported",
MAX_FILE_NAME_LENGTH);
num_of_files = 0;
goto exit;
}
}
}
}
} else if (dir->d_type == DT_DIR && strcmp(dir->d_name, ".") != 0 && strcmp(dir->d_name, "..") != 0) {
/*if it is a directory*/
}
}
/* Re-sort array. This part fills gaps in the array. For example if there is only one file with
* number _4_, the following code will cpy the file name of index 3 of the AFileNames array to
* index 0 (In case AOffset is set to 0) */
if (min_idx != offset) {
for (uint8_t idx = offset; (idx - offset) < num_of_files; idx++) {
strcpy(file_names[idx], file_names[min_idx + idx - offset]);
}
}

exit:
closedir(d);

return num_of_files + offset;
}

std::string convert_to_hex_str(const uint8_t* data, int len) {
std::stringstream string_stream;
string_stream << std::hex;

for (int idx = 0; idx < len; ++idx)
string_stream << std::setw(2) << std::setfill('0') << (int)data[idx];

return string_stream.str();
}

types::iso15118_charger::HashAlgorithm
convert_to_hash_algorithm(const types::evse_security::HashAlgorithm hash_algorithm) {
switch (hash_algorithm) {
Expand Down
68 changes: 0 additions & 68 deletions modules/EvseV2G/tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
#define MAX_FILE_NAME_LENGTH 100
#define MAX_PKI_CA_LENGTH 4 /* leaf up to root certificate */

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif

#ifndef ROUND_UP
#define ROUND_UP(N, S) ((((N) + (S)-1) / (S)) * (S))
#endif
Expand All @@ -32,7 +28,6 @@
#endif

int generate_random_data(void* dest, size_t dest_len);
unsigned int generate_srand_seed(void);

enum Addr6Type {
ADDR6_TYPE_UNPSEC = -1,
Expand All @@ -44,13 +39,10 @@ const char* choose_first_ipv6_interface();
int get_interface_ipv6_address(const char* if_name, enum Addr6Type type, struct sockaddr_in6* addr);

void set_normalized_timespec(struct timespec* ts, time_t sec, int64_t nsec);
int timespec_compare(const struct timespec* lhs, const struct timespec* rhs);
struct timespec timespec_sub(struct timespec lhs, struct timespec rhs);
struct timespec timespec_add(struct timespec lhs, struct timespec rhs);
void timespec_add_ms(struct timespec* ts, long long msec);
long long timespec_to_ms(struct timespec ts);
long long timespec_to_us(struct timespec ts);
int msleep(int ms);
long long int getmonotonictime(void);

/*!
Expand All @@ -61,65 +53,6 @@ long long int getmonotonictime(void);
*/
double calc_physical_value(const int16_t& value, const int8_t& multiplier);

/*!
* \brief range_check_int32 This function checks if an int32 value is within the given range.
* \param min is the min value.
* \param max is the max value.
* \param value which must be checked.
* \return Returns \c true if it is within range, otherwise \c false.
*/
bool range_check_int32(int32_t min, int32_t max, int32_t value);

/*!
* \brief range_check_int64 This function checks if an int64 value is within the given range.
* \param min is the min value.
* \param max is the max value.
* \param value which must be checked.
* \return Returns \c true if it is within range, otherwise \c false.
*/
bool range_check_int64(int64_t min, int64_t max, int64_t value);

/*!
* \brief round_down "round" a string representation of a float down to 1 decimal places
* \param buffer is the float string
* \param len is the length of the buffer
*/
void round_down(const char* buffer, size_t len);

/*!
* \brief get_dir_filename This function searches for a specific name (AFileNameIdentifier) in a file path and stores
* the complete name with file ending in \c AFileName
* \param file_name is the buffer to write the file name.
* \param file_name_len is the length of the buffer.
* \param path is the file path which will be used to search for the specific file.
* \param file_name_identifier is the identifier of the file (file without file ending).
* \return Returns \c true if the file could be found, otherwise \c false.
*/
bool get_dir_filename(char* file_name, uint8_t file_name_len, const char* path, const char* file_name_identifier);

/*!
* \brief get_dir_numbered_file_names This helper-function searches for numbered files in the given file path and stores
* the file names in given char array
* \param file_names is the char array for the findings.
* \param path is the path where the numbered files are stored.
* \param prefix is the prefix of the numbered file.
* \param suffix is the suffix of the numbered file.
* \param offset defines the starting number of the file name.
* \param max_idx is the max index of a file (Between 0-9).
* \return Returns the number of files which where found in the file path.
*/
uint8_t get_dir_numbered_file_names(char file_names[MAX_PKI_CA_LENGTH][MAX_FILE_NAME_LENGTH], const char* path,
const char* prefix, const char* suffix, const uint8_t offset,
const uint8_t max_idx);

/*!
* \brief convert_to_hex_str This function converts a array of binary data to hex string.
* \param data is the array of binary data.
* \param len is length of the array.
* \return Returns the converted string.
*/
std::string convert_to_hex_str(const uint8_t* data, int len);

/**
* \brief convert the given \p hash_algorithm to type types::iso15118_charger::HashAlgorithm
* \param hash_algorithm
Expand All @@ -135,5 +68,4 @@ convert_to_hash_algorithm(const types::evse_security::HashAlgorithm hash_algorit
*/
std::vector<types::iso15118_charger::CertificateHashDataInfo>
convert_to_certificate_hash_data_info_vector(const types::evse_security::OCSPRequestDataList& ocsp_request_data_list);

#endif /* TOOLS_H */
2 changes: 0 additions & 2 deletions modules/EvseV2G/v2g.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ struct v2g_context {
struct event_base* event_base;
pthread_t event_thread;

struct event* com_setup_timeout;

const char* if_name;
struct sockaddr_in6* local_tcp_addr;
struct sockaddr_in6* local_tls_addr;
Expand Down
Loading