2015-04-05 02:11:49 +02:00
|
|
|
|
|
|
|
#include "action.h"
|
2015-04-11 19:00:51 +02:00
|
|
|
#include "dbg.h"
|
2015-04-12 19:19:29 +02:00
|
|
|
#include "log.h"
|
2015-04-19 23:27:44 +02:00
|
|
|
#include "mbag.h"
|
2016-03-11 22:23:00 +01:00
|
|
|
#include "cw.h"
|
2015-04-05 02:11:49 +02:00
|
|
|
|
|
|
|
|
2015-04-26 12:36:53 +02:00
|
|
|
int static check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
|
|
|
|
struct sockaddr *from)
|
2015-04-05 02:11:49 +02:00
|
|
|
{
|
2015-04-19 23:27:44 +02:00
|
|
|
if (len < a->min_len) {
|
|
|
|
cw_dbg(DBG_ELEM_ERR,
|
2016-02-23 19:38:10 +01:00
|
|
|
"%d (%s) message element too short, len=%d, min len=%d",
|
2015-04-19 23:27:44 +02:00
|
|
|
a->elem_id, cw_strelemp(conn->actions, a->elem_id), len,
|
|
|
|
a->min_len);
|
2015-04-05 02:11:49 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2015-04-19 23:27:44 +02:00
|
|
|
if (len > a->max_len) {
|
|
|
|
cw_dbg(DBG_ELEM_ERR,
|
|
|
|
"%d (%s) message element too big, len=%d, max len=%d", a->elem_id,
|
|
|
|
cw_strelemp(conn->actions, a->elem_id), len, a->max_len);
|
2015-04-07 07:42:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2015-04-19 23:27:44 +02:00
|
|
|
|
2015-04-26 12:36:53 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
|
2015-04-26 12:36:53 +02:00
|
|
|
int static do_save(mbag_t itemstore, struct conn *conn, struct cw_action_in *a,
|
|
|
|
uint8_t * data, int len, struct sockaddr *from)
|
|
|
|
{
|
2015-04-19 23:27:44 +02:00
|
|
|
|
|
|
|
if (a->itemtype == MBAG_BYTE) {
|
|
|
|
mbag_set_byte(itemstore, a->item_id, *data);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (a->itemtype == MBAG_WORD) {
|
|
|
|
mbag_set_word(itemstore, a->item_id, cw_get_word(data));
|
|
|
|
return 1;
|
|
|
|
}
|
2018-02-18 14:17:45 +01:00
|
|
|
if (a->itemtype == MTYPE_DWORD) {
|
2015-04-19 23:27:44 +02:00
|
|
|
mbag_set_dword(itemstore, a->item_id, cw_get_dword(data));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (a->itemtype == MBAG_STR) {
|
|
|
|
mbag_set_strn(itemstore, a->item_id, (char *) data, len);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (a->itemtype == MBAG_BSTR) {
|
|
|
|
mbag_set_bstrn(itemstore, a->item_id, data, len);
|
|
|
|
return 1;
|
|
|
|
}
|
2015-04-20 21:28:22 +02:00
|
|
|
|
|
|
|
if (a->itemtype == MBAG_BSTR16) {
|
|
|
|
mbag_set_bstr16n(itemstore, a->item_id, data, len);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
/* if (a->itemtype == MBAG_DATA) {
|
|
|
|
mbag_set_data(itemstore, a->item_id, data, len);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if (a->itemtype == MBAG_VENDORSTR) {
|
2016-03-04 20:20:28 +01:00
|
|
|
mbag_set_bstrv(itemstore, a->item_id,
|
2015-04-26 12:36:53 +02:00
|
|
|
cw_get_dword(data), data + 4, len - 4);
|
2015-04-19 23:27:44 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cw_log(LOG_ERR,
|
|
|
|
"Can't handle item type %d in definition for incomming msg %d (%s) - %d, cw_in_generic.",
|
|
|
|
a->itemtype, a->msg_id, cw_strmsg(a->msg_id), a->elem_id);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
2015-04-26 12:36:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int cw_in_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
|
|
|
|
struct sockaddr *from)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!check_len(conn, a, data, len, from))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
mbag_t itemstore;
|
|
|
|
/// if (!a->target)
|
|
|
|
itemstore = conn->incomming;
|
|
|
|
// else
|
|
|
|
// itemstore = a->target(conn, a);
|
|
|
|
|
|
|
|
|
|
|
|
return do_save(itemstore, conn, a, data, len, from);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2016-03-28 16:44:03 +02:00
|
|
|
/*
|
2015-04-26 12:36:53 +02:00
|
|
|
int cw_in_radio_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
|
|
|
int len, struct sockaddr *from)
|
|
|
|
{
|
2016-03-28 16:44:03 +02:00
|
|
|
// if (!check_len(conn, a, data, len, from))
|
|
|
|
// return 0;
|
2015-04-26 12:36:53 +02:00
|
|
|
|
|
|
|
int rid = cw_get_byte(data);
|
2015-05-01 00:16:54 +02:00
|
|
|
mbag_t radio = mbag_i_get_mbag(conn->radios, rid, NULL);
|
2015-04-26 12:36:53 +02:00
|
|
|
if (!radio) {
|
|
|
|
if (a->vendor_id != 0
|
|
|
|
|| ( (a->vendor_id == 0) && (a->msg_id != CW_MSG_DISCOVERY_REQUEST
|
|
|
|
&& a->msg_id != CW_MSG_JOIN_REQUEST) )) {
|
|
|
|
cw_dbg(DBG_ELEM_ERR, "Radio not found %d", rid);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-05-01 00:16:54 +02:00
|
|
|
mbag_i_set_mbag(conn->radios,rid,mbag_create());
|
2015-04-26 12:36:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-10 17:14:55 +02:00
|
|
|
|
2015-04-12 19:19:29 +02:00
|
|
|
return 1;
|
2015-04-05 02:11:49 +02:00
|
|
|
}
|
2016-03-28 16:44:03 +02:00
|
|
|
|
|
|
|
*/
|