kdriveExpress SDK 23.2.0
kdrive_express_ip_tunneling_secure.c
//
// Copyright (c) 2002-2023 WEINZIERL ENGINEERING GmbH
// All rights reserved.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
// WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
//
#include <stdio.h>
#include <stdlib.h>
#include <kdrive_express.h>
/*******************************
** Main
********************************/
int main(int argc, char* argv[])
{
uint16_t address = 0x901;
uint8_t value = 0;
int32_t ap = 0;
/* Configure the logging level and console logger */
/*
We create a Access Port descriptor. This descriptor is then used for
all calls to that specific access port.
*/
/*
We check that we were able to allocate a new descriptor
This should always happen, unless a bad_alloc exception is internally thrown
which means the memory couldn't be allocated.
*/
{
kdrive_logger(KDRIVE_LOGGER_FATAL, "Unable to create access port. This is a terminal failure");
return -1;
}
/* sets (optional) authentication code */
{
kdrive_logger(KDRIVE_LOGGER_FATAL, "Unable to set the authentication code");
}
/* sets security user id and tunnel password*/
{
kdrive_logger(KDRIVE_LOGGER_FATAL, "Unable to set the password and userid");
}
/* sets preferred ind address */
if (kdrive_ap_set_ip_tunn_requested_ia(ap, 0xCC0C) != KDRIVE_ERROR_NONE) // 0xCC0B=12.12.11
{
kdrive_logger(KDRIVE_LOGGER_FATAL, "Unable to set the requested individual address of the tunnel");
}
/*
Open a Tunneling connection with a specific IP Interface,
you will probably have to change the IP address
*/
if (kdrive_ap_open_ip_tunn(ap, "10.0.0.106", 0, 0) == KDRIVE_ERROR_NONE)
{
/*
Connect the Packet Trace logging mechanism
to see the Rx and Tx packets
*/
/* send a 1-Bit boolean GroupValueWrite telegram: on */
value = 1;
kdrive_ap_group_write(ap, address, &value, 1);
/* send a 1-Bit boolean GroupValueWrite telegram: off */
value = 0;
kdrive_ap_group_write(ap, address, &value, 1);
/* close the access port */
}
/* releases the access port */
return 0;
}
kdriveExpress_API error_t kdrive_ap_set_ip_tunn_credentials(int32_t ap, uint8_t user_id, const char *password)
Sets the user id and the security password for the KNXnet/IP tunneling connection.
kdriveExpress_API error_t kdrive_ap_packet_trace_connect(int32_t ap)
Starts the Packet Trace, for a specific access port.
kdriveExpress_API error_t kdrive_ap_set_ip_tunn_requested_ia(int32_t ap, uint16_t address)
Sets the (optional) requested individual address This function is used for KNXnet/IP v2 devices.
kdriveExpress_API error_t kdrive_ap_group_write(int32_t ap, uint16_t address, const uint8_t *value, uint32_t bits)
Sends a GroupValue_Write Telegram The length is specified in bits to enable values less than one byte...
kdriveExpress_API bool_t kdrive_ap_release(int32_t ap)
Releases the AccessPort interface.
kdriveExpress_API int32_t kdrive_ap_create(void)
Creates an internal AccessPort interface This should be the first function called when working with t...
kdriveExpress_API error_t kdrive_ap_close(int32_t ap)
Closes the access port If the access port is not open nothing happens.
kdriveExpress_API error_t kdrive_ap_open_ip_tunn(int32_t ap, const char *ip_address, uint16_t port, const char *iface_address)
Opens a connection to a KNX IP Tunneling Interface device on a specific network interface or default ...
kdriveExpress_API error_t kdrive_ap_set_ip_tunn_auth_code(int32_t ap, const char *authentication_code)
Sets the optional authentication code for the KNXnet/IP tunneling connection.
kdriveExpress_API void kdrive_logger(uint8_t level, const char *message)
Writes to the kdrive express logger.
kdriveExpress_API void kdrive_logger_console(void)
Sets the logger to write to the console.
kdriveExpress_API void kdrive_logger_set_level(uint8_t level)
Sets the root logger level This is once of:
unsigned short uint16_t
16 bit unsigned char
Definition: kdrive_express_config.h:31
int int32_t
32 bit signed int
Definition: kdrive_express_config.h:35
unsigned char uint8_t
8 bit unsigned char
Definition: kdrive_express_config.h:30
#define KDRIVE_INVALID_DESCRIPTOR
Indicates an invalid descriptor.
Definition: kdrive_express_defs.h:39
#define KDRIVE_ERROR_NONE
No Error, Everything OK.
Definition: kdrive_express_error.h:22
#define KDRIVE_LOGGER_FATAL
A fatal error.
Definition: kdrive_express_logger.h:26
#define KDRIVE_LOGGER_INFORMATION
An informational message, usually denoting the successful completion of an operation.
Definition: kdrive_express_logger.h:31