libp7/src/packet/special.c

60 lines
1.8 KiB
C

/* ************************************************************************** */
/* _____ _ */
/* packet/special.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: libp7 | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2017/01/04 16:39:00 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**
* p7_send_roleswp:
* Invoke a roleswap.
*
* Causes devices to switch roles. Active becomes passive and vice versa.
*
* @arg handle the libp7 handle
* @return if it worked
*/
int p7_send_roleswp(p7_handle_t *handle)
{
/* as we can only send this when we're active, put role to passive */
handle->_active = 0;
/* send packet */
return (p7_send_basic(handle, p7_pt_roleswp, 0, 1));
}
/**
* p7_send_term_because:
* Send termination packet with reason of termination.
*
* @arg handle the libp7 handle.
* @return if it worked.
*/
int p7_send_term_because(p7_handle_t *handle, int reason)
{
handle->_env = NULL;
return (p7_send_basic(handle, p7_pt_terminate, reason, 1));
}
/**
* p7_send_ini_check:
* Initial check sending.
*
* Used to verify if the devices are still connected.
*
* @arg handle the libp7 handle
* @return if it worked
*/
int p7_send_ini_check(p7_handle_t *handle)
{
/* send packet */
log_info("sending check packet...");
return (p7_send_basic(handle, p7_pt_check, 0, 1));
}