70 lines
2.2 KiB
C
70 lines
2.2 KiB
C
/* *****************************************************************************
|
|
* protocol/seven/init.c -- initialize a P7 handle.
|
|
* 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>
|
|
|
|
/**
|
|
* p7_start:
|
|
* Start the communication.
|
|
*
|
|
* @arg handle the handle.
|
|
* @return the error, if any.
|
|
*/
|
|
|
|
int p7_start(p7_handle_t *handle, int check)
|
|
{
|
|
int err = 0;
|
|
log_info("so we're active? let's do what active people do then!");
|
|
|
|
/* send initial check */
|
|
if (check) {
|
|
log_info("sending initial check packet");
|
|
if ((err = p7_send_ini_check(handle))) {
|
|
log_fatal("couldn't send check/didn't receive answer");
|
|
return (err);
|
|
} else if (response.type != p7_pt_ack) {
|
|
log_fatal("received packet wasn't ack, ask your dentist");
|
|
return (p7_error_unknown);
|
|
}
|
|
#if LOGLEVEL <= ll_info
|
|
} else {
|
|
log_info("skipping initial check, we suppose already initialized");
|
|
#endif
|
|
}
|
|
|
|
/* discover environment */
|
|
log_info("checkin' up da environment");
|
|
if ((err = p7_send_cmdsys_getinfo(handle))) {
|
|
log_fatal("couldn't send env query/receive answer");
|
|
return (err);
|
|
} else if (response.type != p7_pt_ack || !response.extended) {
|
|
log_fatal("response to env query wasn't an extended ack packet");
|
|
return (p7_error_unknown);
|
|
}
|
|
|
|
/* save server */
|
|
handle->_server = response.info;
|
|
|
|
/* get environment based on sent hardware id */
|
|
handle->_env = p7_get_env(handle->_server.hwid);
|
|
log_info("environment is '%s'", handle->_env->name);
|
|
|
|
/* no error */
|
|
return (0);
|
|
}
|