cake
/
libp7
Archived
1
0
Fork 1
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libp7/src/protocol/legacy/recv.c.draft

69 lines
2.2 KiB
Plaintext

/* *****************************************************************************
* legacy/recv.c -- receive a legacy packet.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.
* libp7 is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3.0 of the License,
* or (at your option) any later version.
*
* libp7 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libp7; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************** */
#include <libp7/internals.h>
/* ************************************************************************** */
/* Receive the packet */
/* ************************************************************************** */
/**
* p7_legacy_recv:
* Receive a [legacy] packet.
*
* This is the main receiving function for legacy protocol(s).
* It checks the first byte, and if it is a header, it reads the header/part
* using libg1m.
*
* @arg handle the libp7 handle
* @return the error (0 if ok)
*/
static int p7_legacy_recv(p7_handle_t *handle)
{
/* get the first character */
log_info("receiving packet...");
uint8_t byte; if ((err = p7_read(&handle->_stream, &byte, 1)))
return (err);
if (byte != ':') switch (byte) {
/* initial packets */
case 0x15: /* is interactive initial packet */
case 0x16: resp.type = p7_pt_ini; return (0);
/* initial packet response */
case 0x13: resp.type = p7_pt_ini_resp; return (0);
/* ack */
case 0x06: resp.type = p7_pt_ack; return (0);
/* unknown data type */
case 0x00: case 0x24: return (0);
/* checksum error */
case 0x2B: return (0);
/* abort XXX */
case 0x15: return (0);
/* we don't know this */
default: return (p7_error_unknown);
}
/* unknown packet! */
return (p7_error_unknown);
}