Ejemplo n.º 1
1
// ubus call test_ubus helloworld '{"id":1,"msg":"hello","array":["a","b"]}' 
static int test_hello(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req,
	const char *method, struct blob_attr *msg)
{
	struct blob_attr *tb[__HELLO_MAX];
	int tmp_id;
	char *tmp_msg = NULL;
	int len;
	struct blob_attr *attr;
	void *arr;

	blobmsg_parse(hello_policy, __HELLO_MAX, tb, blob_data(msg), blob_len(msg));
	
	
	blob_buf_init(&b, 0);

	if(tb[HELLO_ID])
	{
		tmp_id = blobmsg_get_u32(tb[HELLO_ID]);
		blobmsg_add_u32(&b, "id", tmp_id); 
	}

	if(tb[HELLO_MSG])
	{
		tmp_msg = blobmsg_get_string(tb[HELLO_MSG]);
		blobmsg_add_string(&b, "msg", tmp_msg);
	}

	
	if(tb[HELLO_ARRAY] && blobmsg_type(tb[HELLO_ARRAY]) == BLOBMSG_TYPE_ARRAY)
	{
		arr = blobmsg_open_array(&b, "array");		
		len = blobmsg_data_len(tb[HELLO_ARRAY]);
		__blob_for_each_attr(attr, blobmsg_data(tb[HELLO_ARRAY]), len)
		{
			if (blobmsg_type(attr) == BLOBMSG_TYPE_STRING)
			{
				char *tmp = blobmsg_get_string(attr);
				blobmsg_add_blob(&b, attr);
				printf("array=%s\n", tmp);
			}
		}
		blobmsg_close_array(&b, arr);
	}
Ejemplo n.º 2
0
static int
handle_notify(struct ubus_context *ctx, struct ubus_object *obj,
		struct ubus_request_data *req, const char *method,
		struct blob_attr *msg)
{
	char *str;
	int msg_level;
	const char *info;

	struct blob_attr *tb[__MAN_ALERT_MAX];

	blobmsg_parse(alert_policy, ARRAY_SIZE(alert_policy), tb, blob_data(msg), blob_len(msg));

	if(!tb[MAN_ALERT_MSG_LEVEL] || !tb[MAN_ALERT_MSG_INFO]){
		fprintf(stderr, "Received illegal notification\n");
		return -1;
	}
	msg_level = blobmsg_get_u16(tb[MAN_ALERT_MSG_LEVEL]);
	info = blobmsg_get_string(tb[MAN_ALERT_MSG_INFO]);

/*
	str = blobmsg_format_json(msg, true);
	fprintf(stderr, "Received notification '%s': %s\n", method, str);
	free(str);
*/
	asyncResult->notify_cb( method, msg_level, info);	

	return 0;
}
Ejemplo n.º 3
0
/*
 *	add ports to aggregation group.
 *	msg : {"aggid":xxx,
 *			"ports": [
 *				{"portNumber":x},
 *				{"portNumber":x},
 *				{"portNumber":x}
 *			]
 *		  }
 * */
static int aggregation_add_port(struct ubus_context *ctx, struct ubus_object *obj,
		      struct ubus_request_data *req, const char *method,
		      struct blob_attr *msg)
{
	struct blob_attr *tb[__AGGREGATION_ADD_PORT_MAX];
	//struct blob_attr *tbPortList[__AGGREGATION_ADD_PORT_LIST_MAX];
	char *dev = NULL;
	int aggID;
	struct blob_attr *cur;
	int portCnt = 0;
	int rem;
	struct portAttr port;
	//TODO:

	blobmsg_parse(aggregation_add_port_policy, ARRAY_SIZE(aggregation_add_port_policy), tb, blob_data(msg), blob_len(msg));
	
	if(!tb[AGGREGATION_ADD_PORT_GROUP_ID] || !tb[AGGREGATION_ADD_PORT_PORTS])
		return UBUS_STATUS_INVALID_ARGUMENT;

	aggID = blobmsg_get_u32(tb[AGGREGATION_ADD_PORT_GROUP_ID]);
	

	if(tb[AGGREGATION_ADD_PORT_DEVICE])
		dev = blobmsg_get_string(tb[AGGREGATION_ADD_PORT_DEVICE]);

	cur = tb[AGGREGATION_ADD_PORT_GROUP_ID];

	blobmsg_for_each_attr(cur,tb[AGGREGATION_ADD_PORT_PORTS], rem) {
		//get port number
		get_port_attr(&port, cur);
	//	printf("%s, port = %x\n",__func__, port.number);
		// TODO: add port to aggid
	}
Ejemplo n.º 4
0
static void create_vlan_callback(struct ubus_request *req, int type, struct blob_attr *msg)
{
	char *str = NULL;
	struct Rmsg;
	struct blob_attr *tb[__FRAMEWORK_MAX];
	struct json_object *new_obj;

	blobmsg_parse(framework_result_policy, ARRAY_SIZE(framework_result_policy), tb, blob_data(msg), blob_len(msg));
	Rmsg.msg = blobmsg_get_string(tb[FRAMEWORK_RESULT_MSG]);
	Rmsg.resCode = (int)blobmsg_get_u16(tb[FRAMEWORK_RESULT_CODE]);

	new_obj = json_tokener_parse(Rmsg.msg);

	if(Rmsg.resCode == LR_ERR_NONE){
		/* success add new vlan entry */
		if(new_obj){
			struct json_object *o = json_object_object_get(new_obj,"vlanID");
			u16 vid = json_object_get_int(o);
			new_vlan_software(vid);
			json_object_put(o);
			json_object_put(new_obj);
			Rmsg.msg = "";
		}

	}
	if((asyncResult == NULL) || (asyncResult->result_data_cb == NULL)){
		str = blobmsg_format_json(msg, true);
		printf("%s\n",str);
		free(str);
	}else{
		asyncResult->result_data_cb(&Rmsg);
	}
}
Ejemplo n.º 5
0
static int vlan_delete(struct ubus_context *ctx, struct ubus_object *obj,
		struct ubus_request_data *req, const char *method,
		struct blob_attr *msg)
{
	struct blob_attr *tb[__VLAN_DELETE_MAX];
	u8 mode = 0;

	int resCode = LR_SUCCESS;
	const char *pmsg =  getJsonMsg(LR_INVALID_PARAM);
	json_object *result = NULL;
	result = json_object_new_object();

	blobmsg_parse(vlan_delete_policy, ARRAY_SIZE(vlan_delete_policy), tb, blob_data(msg), blob_len(msg));

	if(!tb[VLAN_DELETE_MODE]){
		resCode = LR_INVALID_PARAM;
		goto returnMsg;
	}
	mode = blobmsg_get_u8(tb[VLAN_DELETE_MODE]);
	if(mode){
		int vid;
		if(!tb[VLAN_DELETE_ID]){
			resCode = LR_INVALID_PARAM;
			goto returnMsg;
		}
		vid  = blobmsg_get_u16(tb[VLAN_DELETE_ID]);
		resCode = delete_vlan_in_vlanDatabase(vid);

		if(resCode != LR_ERR_NONE){
			pmsg = getJsonMsg(resCode);
			goto returnMsg;
		}
		json_object_object_add(result, "vlanID", json_object_new_int(vid));

	}else{
		/* delete all vlan */
		resCode = delete_all_vlan_in_vlanDatabase();
		if(resCode != LR_ERR_NONE){
			pmsg = getJsonMsg(resCode);
			goto returnMsg;
		}
		json_object_object_add(result, "flush", json_object_new_int(1));

	}
	pmsg = json_object_to_json_string(result);


returnMsg:
	blob_buf_init(&b, 0);
	blobmsg_add_string(&b, "msg",pmsg);
	blobmsg_add_u16(&b,"resCode", resCode);

	req->deferred = false;
	ubus_send_reply(ctx, req, b.head);
	if(result != NULL)
		json_object_put(result);

	return UBUS_STATUS_OK;

}
Ejemplo n.º 6
0
Archivo: juci.c Proyecto: schuza/juci
static int
rpc_juci_backup_config_set(struct ubus_context *ctx, struct ubus_object *obj,
                            struct ubus_request_data *req, const char *method,
                            struct blob_attr *msg)
{
	FILE *f;
	struct blob_attr *tb[__RPC_D_MAX];

	blobmsg_parse(rpc_data_policy, __RPC_D_MAX, tb,
	              blob_data(msg), blob_len(msg));

	if (!tb[RPC_D_DATA])
		return UBUS_STATUS_INVALID_ARGUMENT;

	if (blobmsg_data_len(tb[RPC_D_DATA]) >= 2048)
		return UBUS_STATUS_NOT_SUPPORTED;

	if (!(f = fopen("/etc/sysupgrade.conf", "w")))
		return rpc_errno_status();

	fwrite(blobmsg_data(tb[RPC_D_DATA]),
	       blobmsg_data_len(tb[RPC_D_DATA]) - 1, 1, f);

	fclose(f);
	return 0;
}
Ejemplo n.º 7
0
static int aggregation_enable(struct ubus_context *ctx, struct ubus_object *obj,
		      struct ubus_request_data *req, const char *method,
		      struct blob_attr *msg)
{
	struct blob_attr *tb[__AGGREGATION_MAX];
	bool en;
	int fds[2];

	blobmsg_parse(aggregation_enable_policy, ARRAY_SIZE(aggregation_enable_policy), tb, blob_data(msg), blob_len(msg));
	
	if(!tb[AGGREGATION_MODULE_ENABLE])
		return UBUS_STATUS_INVALID_ARGUMENT;

	en = blobmsg_get_bool(tb[AGGREGATION_MODULE_ENABLE]);

	// TODO:check aggregation module is found, set enable status to require.
	DEBUG("%s received enable message:%s\n", obj->name, en?"true":"false");

	{
		int resCode = LR_SUCCESS;
		char msg[100];
		char *pmsg = msg;
		//	TODO: add other attr


		sprintf(msg,"set aggregation module to %s", en ? "true":"false");

		blob_buf_init(&b, 0);
		//blobmsg_add_u8(&b, "module_en",en);
		blobmsg_add_string(&b, "msg", pmsg);
		blobmsg_add_u16(&b, "resCode", resCode);

		req->deferred = false;
		ubus_send_reply(ctx, req, b.head);


	}
#if 0
	if(pipe(fds) == -1) {
		fprintf(stderr, "Failed to create pipe\n");
		return -1;
	}

	ubus_request_set_fd(ctx, req, fds[0]);
	ubus_complete_deferred_request(ctx, req, 0);

	{
		char data[100]={0};
		sprintf(data, "module %s\n", en ? "enable" : "disable" );
		if(write(fds[1], data, strlen(data) ) < 0) {
			close(fds[1]);
			free(req);
			return 0;
		} 
	}
#endif

	return 0;
}
Ejemplo n.º 8
0
static void dump_cb(struct ubus_request *req, int type, struct blob_attr *msg)
{
	static const struct blobmsg_policy policy = { "interface", BLOBMSG_TYPE_ARRAY };
	struct blob_attr *cur;

	blobmsg_parse(&policy, 1, &cur, blob_data(msg), blob_len(msg));
	if (cur)
		interfaces = blob_memdup(cur);
}
Ejemplo n.º 9
0
void get_port_attr(struct portAttr *port, struct blob_attr *msg)
{
	struct blob_attr *tb[__PORT_MAX];
	int portNum;
	blobmsg_parse(port_policy, ARRAY_SIZE(port_policy), tb, blobmsg_data(msg), blobmsg_len(msg));
	if(tb[AGG_PORT_NUMBER])
		port->number =  blobmsg_get_u32(tb[AGG_PORT_NUMBER]);
	if(tb[AGG_PORT_ALIAS])
		port->alias =  blobmsg_get_string(tb[AGG_PORT_ALIAS]);
	return;
}
Ejemplo n.º 10
0
struct env_var *uh_get_process_vars(struct client *cl, struct path_info *pi)
{
	struct http_request *req = &cl->request;
	struct blob_attr *data = cl->hdr.head;
	struct env_var *vars = (void *) uh_buf;
	struct blob_attr *tb[__HDR_MAX];
	const char *url;
	int len;
	int i;

	url = blobmsg_data(blob_data(cl->hdr.head));
	len = ARRAY_SIZE(proc_header_env);
	len += ARRAY_SIZE(extra_vars);
	len *= sizeof(struct env_var);

	BUILD_BUG_ON(sizeof(uh_buf) < len);

	extra_vars[VAR_SCRIPT_NAME].value = pi->name;
	extra_vars[VAR_SCRIPT_FILE].value = pi->phys;
	extra_vars[VAR_DOCROOT].value = pi->root;
	extra_vars[VAR_QUERY].value = pi->query ? pi->query : "";
	extra_vars[VAR_REQUEST].value = url;
	extra_vars[VAR_PROTO].value = http_versions[req->version];
	extra_vars[VAR_METHOD].value = http_methods[req->method];
	extra_vars[VAR_PATH_INFO].value = pi->info;
	extra_vars[VAR_USER].value = req->realm ? req->realm->user : NULL;
	extra_vars[VAR_HTTPS].value = cl->tls ? "on" : NULL;

	snprintf(redirect_status, sizeof(redirect_status),
		 "%d", req->redirect_status);
	inet_ntop(cl->srv_addr.family, &cl->srv_addr.in, local_addr, sizeof(local_addr));
	snprintf(local_port, sizeof(local_port), "%d", cl->srv_addr.port);
	inet_ntop(cl->peer_addr.family, &cl->peer_addr.in, remote_addr, sizeof(remote_addr));
	snprintf(remote_port, sizeof(remote_port), "%d", cl->peer_addr.port);

	blobmsg_parse(hdr_policy, __HDR_MAX, tb, blob_data(data), blob_len(data));
	for (i = 0; i < ARRAY_SIZE(proc_header_env); i++) {
		struct blob_attr *cur;

		cur = tb[proc_header_env[i].idx];
		vars[i].name = proc_header_env[i].name;
		vars[i].value = cur ? blobmsg_data(cur) : "";
	}

	memcpy(&vars[i], extra_vars, sizeof(extra_vars));
	i += ARRAY_SIZE(extra_vars);
	vars[i].name = NULL;
	vars[i].value = NULL;

	return vars;
}
Ejemplo n.º 11
0
static int
easycwmpd_handle_command(struct ubus_context *ctx, struct ubus_object *obj,
			 struct ubus_request_data *req, const char *method,
			 struct blob_attr *msg)
{
	struct blob_attr *tb[__COMMAND_MAX];

	blobmsg_parse(command_policy, ARRAY_SIZE(command_policy), tb,
			  blob_data(msg), blob_len(msg));

	if (!tb[COMMAND_NAME])
		return UBUS_STATUS_INVALID_ARGUMENT;

	blob_buf_init(&b, 0);

	char *cmd = blobmsg_data(tb[COMMAND_NAME]);
	char *info;

	if (!strcmp("reload", cmd)) {
		log_message(NAME, L_NOTICE, "triggered ubus reload\n");
		easycwmp_reload();
		blobmsg_add_u32(&b, "status", 0);
		if (asprintf(&info, "easycwmpd reloaded") == -1)
			goto error;
	} else if (!strcmp("stop", cmd)) {
		log_message(NAME, L_NOTICE, "triggered ubus stop\n");
		ubus_timer.cb = ubus_easycwmpd_stop_callback;
		uloop_timeout_set(&ubus_timer, 1000);
		blobmsg_add_u32(&b, "status", 0);
		if (asprintf(&info, "easycwmpd stopped") == -1)
			goto error;
	} else {
		blobmsg_add_u32(&b, "status", -1);
		if (asprintf(&info, "%s command is not supported", cmd) == -1)
			goto error;
	}

	blobmsg_add_string(&b, "info", info);
	free(info);

	ubus_send_reply(ctx, req, b.head);

	blob_buf_free(&b);
	return 0;

error:
	blob_buf_free(&b);
	return -1;

}
Ejemplo n.º 12
0
Archivo: conf.c Proyecto: Oryon/pimbd
static int conf_rpa_flush(struct ipc_user *u, char *data, size_t len, __unused struct blob_buf *reply)
{
	conf conf = container_of(u, conf_s, ipc_users[CONF_IPC_RPA_FLUSH]);
	struct blob_attr *tb[CONF_RPA_MAX];
	struct in6_addr rpa;

	if(blobmsg_parse(conf_rpa_attrs, CONF_RPA_MAX, tb, data, len) ||
			!tb[CONF_RPA_RPA] || !addr_pton(&rpa, blobmsg_get_string(tb[CONF_RPA_RPA])) ||
			tb[CONF_RPA_GROUPS] || tb[CONF_RPA_RPL_JP])
		return -EINVAL;

	pim_rpa_update(conf->pim, &rpa);
	pim_rpa_flush(conf->pim, &rpa);
	return 0;
}
Ejemplo n.º 13
0
Archivo: conf.c Proyecto: Oryon/pimbd
static int conf_rpa_set(struct ipc_user *u, char *data, size_t len, __unused struct blob_buf *reply)
{
	conf conf = container_of(u, conf_s, ipc_users[CONF_IPC_RPA_SET]);
	struct blob_attr *tb[CONF_RPA_MAX];
	struct in6_addr rpa;

	if(blobmsg_parse(conf_rpa_attrs, CONF_RPA_MAX, tb, data, len) ||
			!tb[CONF_RPA_RPA] || !addr_pton(&rpa, blobmsg_get_string(tb[CONF_RPA_RPA])) ||
			tb[CONF_RPA_GROUPS])
		return -1;

	if(tb[CONF_RPA_RPL_JP])
		pim_rpa_set_rpl_jp(conf->pim, &rpa, blobmsg_get_u8(tb[CONF_RPA_RPL_JP]));

	return 0;
}
Ejemplo n.º 14
0
static int vlan_new(struct ubus_context *ctx, struct ubus_object *obj,
		struct ubus_request_data *req, const char *method,
		struct blob_attr *msg)
{
	struct blob_attr *tb[__VLAN_NEW_MAX];
	int vid;
	u8 mstid = 0;

	int resCode = LR_ERR_NONE;
	const char *pmsg =  getJsonMsg(LR_INVALID_PARAM);
	json_object *result = NULL;

	blobmsg_parse(vlan_new_policy, ARRAY_SIZE(vlan_new_policy), tb, blob_data(msg), blob_len(msg));

	if(!tb[VLAN_NEW_ID]){
		resCode = LR_INVALID_PARAM;
		goto returnMsg;
	}

	if(tb[VLAN_NEW_MSTID]){
		mstid = blobmsg_get_u8(tb[VLAN_NEW_MSTID]);
	}

	vid  = blobmsg_get_u16(tb[VLAN_NEW_ID]);
	//resCode = create_vlan_have_none_port(vid);
	resCode = create_vlan_have_none_port_ex(vid, mstid);
	if(resCode != LR_ERR_NONE){
		pmsg = getJsonMsg(resCode);
	}else{
		result = json_object_new_object();
		json_object_object_add(result, "vlanID", json_object_new_int(vid));
		pmsg = json_object_to_json_string(result);
	}


returnMsg:
	blob_buf_init(&b, 0);
	blobmsg_add_string(&b, "msg",pmsg);
	blobmsg_add_u16(&b,"resCode", resCode);

	req->deferred = false;
	ubus_send_reply(ctx, req, b.head);
	if(result != NULL)
		json_object_put(result);

	return UBUS_STATUS_OK;
}
Ejemplo n.º 15
0
static int proc_signal(struct ubus_context *ctx, struct ubus_object *obj,
			struct ubus_request_data *req, const char *method,
			struct blob_attr *msg)
{
	struct blob_attr *tb[__SIGNAL_MAX];

	if (!msg)
		return UBUS_STATUS_INVALID_ARGUMENT;

	blobmsg_parse(signal_policy, __SIGNAL_MAX, tb, blob_data(msg), blob_len(msg));
	if (!tb[SIGNAL_PID || !tb[SIGNAL_NUM]])
		return UBUS_STATUS_INVALID_ARGUMENT;

	kill(blobmsg_get_u32(tb[SIGNAL_PID]), blobmsg_get_u32(tb[SIGNAL_NUM]));

	return 0;
}
Ejemplo n.º 16
0
static int aggregation_create_group(struct ubus_context *ctx, struct ubus_object *obj,
		      struct ubus_request_data *req, const char *method,
		      struct blob_attr *msg)
{
	struct blob_attr *tb[__AGGREGATION_GROUP_MAX];
	char *dev = NULL;
	int aggID;
	char *aggType = NULL;
	char *aggDesc = NULL;


	blobmsg_parse(aggregation_group_policy, ARRAY_SIZE(aggregation_group_policy), tb, blob_data(msg), blob_len(msg));
	
	if(!tb[AGGREGATION_GROUP_ID])
		return UBUS_STATUS_INVALID_ARGUMENT;

	aggID = blobmsg_get_u32(tb[AGGREGATION_GROUP_ID]);

	if(tb[AGGREGATION_GROUP_DEVICE])
		dev = blobmsg_get_string(tb[AGGREGATION_GROUP_DEVICE]);

	if(tb[AGGREGATION_GROUP_TYPE])
		aggType = blobmsg_get_string(tb[AGGREGATION_GROUP_TYPE]);

	if(tb[AGGREGATION_GROUP_DESC])
		aggDesc = blobmsg_get_string(tb[AGGREGATION_GROUP_DESC]);

	// TODO:do create new aggregation group.
	// dev used when system have more 1 VxBOX device.
	DPRINTF("%s received create aggregation group message: \ 
dev = %s, aggid = %d, aggType=%s, aggDesc=%s \n", obj->name, dev, aggID,aggType, aggDesc);


	blob_buf_init(&b, 0);
	blobmsg_add_u16(&b, "aggregation id",aggID);
	if (aggType)
		blobmsg_add_string(&b, "aggregation type",aggType);
	if (aggDesc)
		blobmsg_add_string(&b, "aggregation description",aggDesc);
//	TODO: add other attr
	
	req->deferred = false;
	ubus_send_reply(ctx, req, b.head);
	return 0;

}
Ejemplo n.º 17
0
static int nand_set(struct ubus_context *ctx, struct ubus_object *obj,
			struct ubus_request_data *req, const char *method,
			struct blob_attr *msg)
{
	struct blob_attr *tb[__NAND_MAX];

	if (!msg)
		return UBUS_STATUS_INVALID_ARGUMENT;

	blobmsg_parse(nand_policy, __NAND_MAX, tb, blob_data(msg), blob_len(msg));
	if (!tb[NAND_PATH])
		return UBUS_STATUS_INVALID_ARGUMENT;

	procd_spawn_upgraded(blobmsg_get_string(tb[NAND_PATH]));
	fprintf(stderr, "Yikees, something went wrong. no /sbin/upgraded ?\n");
	return 0;
}
Ejemplo n.º 18
0
static int handle_loglevel_update(struct ubus_context *ctx, struct ubus_object *obj,
        struct ubus_request_data *req, const char *method,
        struct blob_attr *msg)
{
    struct blob_attr *tb[__LOGLEVEL_MAX];
    char *log_buf = NULL;
    char cmd[128] = {0};

    cloudc_debug("%s[%d]: Enter ", __func__, __LINE__);
    blobmsg_parse(handle_loglevel_policy, ARRAY_SIZE(handle_loglevel_policy), tb, blob_data(msg), blob_len(msg));

    if (tb[LOGLEVEL])
    {
        log_buf = blobmsg_data(tb[LOGLEVEL]);

        if ( NULL != strcasestr(log_buf, "debug"))
        {
            cloudc_log_level_int = LOG_LEVEL_DEBUG;
        }
        else if ( NULL != strcasestr(log_buf, "error"))
        {
            cloudc_log_level_int = LOG_LEVEL_ERR;
        }
        else
        {
            cloudc_error("%s[%d]: parameter should only be debug or error, please double check", __func__, __LINE__);
        }

        snprintf(cmd, sizeof(cmd), "uci set cloudc.global.loglevel=\"%s\"",log_buf);
        system(cmd);
        system("uci commit");
        cloudc_debug("%s[%d]: cmd = %s\n", __func__, __LINE__, cmd);

        cloudc_debug("%s[%d]: cloudc_log_level_int = %d", __func__, __LINE__, cloudc_log_level_int);
    }

    else
    {
        cloudc_debug("%s[%d]: wrong parameter,please double check", __func__, __LINE__);
    }

    cloudc_debug("%s[%d]: Exit ", __func__, __LINE__);
    return 0;
}
Ejemplo n.º 19
0
Archivo: conf.c Proyecto: Oryon/pimbd
static int conf_rpa_mod(conf conf, char *data, size_t len, __unused struct blob_buf *reply, bool del)
{
	struct blob_attr *tb[CONF_RPA_MAX];
	struct in6_addr rpa;
	struct in6_addr gr;
	uint8_t plen;

	if(blobmsg_parse(conf_rpa_attrs, CONF_RPA_MAX, tb, data, len) ||
			!tb[CONF_RPA_RPA] || !addr_pton(&rpa, blobmsg_get_string(tb[CONF_RPA_RPA])) ||
			!tb[CONF_RPA_GROUPS] || !prefix_pton(&gr, &plen, blobmsg_get_string(tb[CONF_RPA_GROUPS])) ||
			!addr_is_multicast(&gr) || tb[CONF_RPA_RPL_JP])
		return -EINVAL;

	if(del)
		pim_rpa_del(conf->pim, &rpa, &gr, plen);
	else
		pim_rpa_add(conf->pim, &rpa, &gr, plen);
	return 0;
}
Ejemplo n.º 20
0
static int sw_reg_write(struct ubus_context *ctx, struct ubus_object *obj,
		struct ubus_request_data *req, const char *method,
		struct blob_attr *msg)
{
	struct blob_attr *tb[__SW_REG_WRITE_MAX];
	u8 phyAddr;
	u8 regAddr;
	u16 data;

	int resCode = LR_SUCCESS;
	const char *pmsg =  getJsonMsg(LR_INVALID_PARAM);

	blobmsg_parse(sw_reg_write_policy, ARRAY_SIZE(sw_reg_write_policy), tb, blob_data(msg), blob_len(msg));

	if(!tb[SW_REG_WRITE_REG_ADDR] || !tb[SW_REG_WRITE_ADDR] || !tb[SW_REG_WRITE_DATA]){
		resCode = LR_INVALID_PARAM;
		goto returnMsg;

	}

	phyAddr  = blobmsg_get_u8(tb[SW_REG_WRITE_ADDR]);
	regAddr = blobmsg_get_u8(tb[SW_REG_WRITE_REG_ADDR]);
	data = blobmsg_get_u16(tb[SW_REG_WRITE_DATA]);
	
	resCode = sw_chip_register_write_reg(phyAddr, regAddr, (int)data);

	char buff[100];
	sprintf(buff, "{\"phyAddr\":0x%2x, \"regAddr\":0x%2x, \"value\":0x%4x}", phyAddr,regAddr, data);
	pmsg = buff;

		
	//pmsg= getJsonMsg(resCode);

returnMsg:
	blob_buf_init(&b, 0);
	blobmsg_add_string(&b, "msg",pmsg);
	blobmsg_add_u16(&b,"resCode", resCode);

	req->deferred = false;
	ubus_send_reply(ctx, req, b.head);

	return UBUS_STATUS_OK;
}
Ejemplo n.º 21
0
static void vlanlist_checkout_callback(struct ubus_request *req, int type, struct blob_attr *msg)
{
	char *str = NULL;
	struct Rmsg;
	struct blob_attr *tb[__FRAMEWORK_MAX];
	struct json_object *new_obj;

	blobmsg_parse(framework_result_policy, ARRAY_SIZE(framework_result_policy), tb, blob_data(msg), blob_len(msg));
	Rmsg.msg = blobmsg_get_string(tb[FRAMEWORK_RESULT_MSG]);
	Rmsg.resCode = (int)blobmsg_get_u16(tb[FRAMEWORK_RESULT_CODE]);

	//printf("%s\n", Rmsg.msg);
	new_obj = json_tokener_parse(Rmsg.msg);
	if(Rmsg.resCode != LR_ERR_NONE){
		if(new_obj){
			const char *errmsg = NULL;
			struct json_object *o = json_object_object_get(new_obj,"ERROR");
			errmsg = json_object_get_string(o);
			if(errmsg != NULL)
				fprintf(stderr,"%s",errmsg);
			json_object_put(o);
			json_object_put(new_obj);
		}
	}else{
		if(new_obj){
			struct json_object *o = json_object_object_get(new_obj, "vlanlist");
			// vlanlist is a array
			if(json_object_is_type(o, json_type_array)){
				int length=json_object_array_length(o);
				int i = 0;
				u16 *pVids = (u16 *)malloc(sizeof(u16) * length);
				for(i=0; i<length; i++) {
					json_object *val=json_object_array_get_idx(o,i);
					*(pVids+i) = json_object_get_int(val);
				}
				copy_vlanlist_software(pVids, length);
				free(pVids);
			}

		}
	}

}
Ejemplo n.º 22
0
static int
easycwmpd_handle_inform(struct ubus_context *ctx, struct ubus_object *obj,
			struct ubus_request_data *req, const char *method,
			struct blob_attr *msg)
{
	int tmp;
	struct blob_attr *tb[__INFORM_MAX];

	blobmsg_parse(inform_policy, ARRAY_SIZE(inform_policy), tb,
			  blob_data(msg), blob_len(msg));

	if (!tb[INFORM_EVENT])
		return UBUS_STATUS_INVALID_ARGUMENT;

	log_message(NAME, L_NOTICE, "triggered ubus inform %s\n",
			blobmsg_data(tb[INFORM_EVENT]));
	tmp = cwmp_get_int_event_code(blobmsg_data(tb[INFORM_EVENT]));
	cwmp_connection_request(tmp);

	return 0;
}
Ejemplo n.º 23
0
static int aggregation_set_sys_pri(struct ubus_context *ctx, struct ubus_object *obj,
		      struct ubus_request_data *req, const char *method,
		      struct blob_attr *msg)
{
	struct blob_attr *tb[__AGGREGATION_PRI_MAX];
	char *dev = NULL;
	int sysPri;
	int fds[2];

	blobmsg_parse(aggregation_sys_pri_policy, ARRAY_SIZE(aggregation_sys_pri_policy), tb, blob_data(msg), blob_len(msg));
	
	if(!tb[AGGREGATION_SYS_PRI])
		return UBUS_STATUS_INVALID_ARGUMENT;

	if(tb[AGGREGATION_DEVICE])
		dev = blobmsg_get_string(tb[AGGREGATION_DEVICE]);


	sysPri = blobmsg_get_u32(tb[AGGREGATION_SYS_PRI]);


	// TODO:do set aggregation system priority.
	// dev used when system have more 1 VxBOX device.
	DPRINTF("%s received set aggregation system priority message: \ 
dev = %s, system Priority = %d \n", obj->name, dev, sysPri);


//	ubus_defer_request(ctx, req, &hreq->req);

	blob_buf_init(&b, 0);
//	blobmsg_add_string(&b, "device",dev);
	blobmsg_add_u16(&b, "system priority",sysPri);
//	TODO: add other attr
	
	req->deferred = false;
	ubus_send_reply(ctx, req, b.head);
	

	return 0;
}
Ejemplo n.º 24
0
static void swVlan_result_data(struct ubus_request *req, int type, struct blob_attr *msg)
{
	char *str = NULL;
	struct Rmsg;
	struct blob_attr *tb[__FRAMEWORK_MAX];

	//pthread_mutex_lock(&gClient->client_cb_mutex);
	blobmsg_parse(framework_result_policy, ARRAY_SIZE(framework_result_policy), tb, blob_data(msg), blob_len(msg));
	Rmsg.msg = blobmsg_get_string(tb[FRAMEWORK_RESULT_MSG]);
	Rmsg.resCode = blobmsg_get_u16(tb[FRAMEWORK_RESULT_CODE]);
	
	if((asyncResult == NULL) || (asyncResult->result_data_cb == NULL)){
		str = blobmsg_format_json(msg, true);
		printf("%s\n",str);
		free(str);
	}else{
		asyncResult->result_data_cb(&Rmsg);
	}
	//pthread_mutex_unlock(&gClient->client_cb_mutex);

	return;
}
Ejemplo n.º 25
0
Archivo: juci.c Proyecto: schuza/juci
static int
rpc_juci_backup_restore(struct ubus_context *ctx, struct ubus_object *obj,
                         struct ubus_request_data *req, const char *method,
                         struct blob_attr *msg)
{
	struct blob_attr *tb[__RPC_BACKUP_MAX];
	
	blobmsg_parse(rpc_backup_policy, __RPC_BACKUP_MAX, tb,
	              blob_data(msg), blob_len(msg));
	
	struct blob_attr *pass = tb[RPC_BACKUP_PASSWORD]; 
	
	if (pass && blobmsg_data_len(pass) > 0 && blobmsg_data(pass) && strlen(blobmsg_data(pass)) > 0){
		const char *cmd[] = { "sysupgrade", "--restore-backup",
	                       "/tmp/backup.tar.gz", "--password", blobmsg_data(pass), NULL };

		return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req);
	} 
	
	const char *cmd[] = { "sysupgrade", "--restore-backup",
						   "/tmp/backup.tar.gz", NULL };

	return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req);
}
Ejemplo n.º 26
0
Archivo: conf.c Proyecto: Oryon/pimbd
static int conf_proxy_mod(conf conf, char *data, size_t len, __unused struct blob_buf *reply, bool del)
{
	struct blob_attr* tb[CONF_PROXY_MAX];
	int iport;
	const char* saddr;
	struct in6_addr addr;

	if (blobmsg_parse(conf_proxy_attrs, CONF_PROXY_MAX, tb, data, len))
		return -1;

	if(!tb[CONF_PROXY_ADDR] || !tb[CONF_PROXY_PORT] ||
			!(saddr = blobmsg_get_string(tb[CONF_PROXY_ADDR])) ||
			!(iport = blobmsg_get_u32(tb[CONF_PROXY_PORT])))
		return -EINVAL;
	if(!(addr_pton(&addr, saddr)) || iport >= 65535 || iport <= 0)
		return -EINVAL;

	if(del) {
		pim_ctl_del_proxy(conf->pim, &addr, (in_port_t) iport);
	} else {
		pim_ctl_add_proxy(conf->pim, &addr, (in_port_t) iport);
	}
	return 0;
}
Ejemplo n.º 27
0
static int
freecwmpd_handle_notify(struct ubus_context *ctx, struct ubus_object *obj,
			struct ubus_request_data *req, const char *method,
			struct blob_attr *msg)
{
	struct blob_attr *tb[__NOTIFY_MAX];

	blobmsg_parse(notify_policy, ARRAY_SIZE(notify_policy), tb,
		      blob_data(msg), blob_len(msg));

	if (!tb[NOTIFY_PARAM])
		return UBUS_STATUS_INVALID_ARGUMENT;

	if (!tb[NOTIFY_VALUE])
		return UBUS_STATUS_INVALID_ARGUMENT;

	freecwmp_log_message(NAME, L_NOTICE,
			     "triggered ubus notification parameter %s\n",
			     blobmsg_data(tb[NOTIFY_PARAM]));
	cwmp_add_notification(blobmsg_data(tb[NOTIFY_PARAM]),
			      blobmsg_data(tb[NOTIFY_VALUE]));

	return 0;
}
Ejemplo n.º 28
0
static struct device_addr *
parse_address_item(struct blob_attr *attr, bool v6, bool ext)
{
	struct device_addr *addr;
	struct blob_attr *tb[__ADDR_MAX];
	struct blob_attr *cur;

	if (blobmsg_type(attr) != BLOBMSG_TYPE_TABLE)
		return NULL;

	addr = alloc_device_addr(v6, ext);
	if (!addr)
		return NULL;

	blobmsg_parse(proto_ip_addr, __ADDR_MAX, tb, blobmsg_data(attr), blobmsg_data_len(attr));

	addr->mask = v6 ? 128 : 32;
	if ((cur = tb[ADDR_MASK])) {
		unsigned int new_mask;

		new_mask = parse_netmask_string(blobmsg_data(cur), v6);
		if (new_mask > addr->mask)
			goto error;

		addr->mask = new_mask;
	}

	cur = tb[ADDR_IPADDR];
	if (!cur)
		goto error;

	if (!inet_pton(v6 ? AF_INET6 : AF_INET, blobmsg_data(cur), &addr->addr))
		goto error;

	if ((cur = tb[ADDR_OFFLINK]) && blobmsg_get_bool(cur))
		addr->flags |= DEVADDR_OFFLINK;

	if (!v6) {
		if ((cur = tb[ADDR_BROADCAST]) &&
		    !inet_pton(AF_INET, blobmsg_data(cur), &addr->broadcast))
			goto error;
		if ((cur = tb[ADDR_PTP]) &&
		    !inet_pton(AF_INET, blobmsg_data(cur), &addr->point_to_point))
			goto error;
	} else {
		time_t now = system_get_rtime();
		if ((cur = tb[ADDR_PREFERRED])) {
			int64_t preferred = blobmsg_get_u32(cur);
			int64_t preferred_until = preferred + (int64_t)now;
			if (preferred_until <= LONG_MAX && preferred != 0xffffffffLL)
				addr->preferred_until = preferred_until;
		}

		if ((cur = tb[ADDR_VALID])) {
			int64_t valid = blobmsg_get_u32(cur);
			int64_t valid_until = valid + (int64_t)now;
			if (valid_until <= LONG_MAX && valid != 0xffffffffLL)
				addr->valid_until = valid_until;

		}

		if (addr->valid_until) {
			if (!addr->preferred_until)
				addr->preferred_until = addr->valid_until;
			else if (addr->preferred_until > addr->valid_until)
				goto error;
		}

		if ((cur = tb[ADDR_CLASS]))
			addr->pclass = strdup(blobmsg_get_string(cur));
	}

	return addr;

error:
	free(addr);
	return NULL;
}
Ejemplo n.º 29
0
static int vlan_mstp(struct ubus_context *ctx, struct ubus_object *obj,
		struct ubus_request_data *req, const char *method,
		struct blob_attr *msg)
{
	struct blob_attr *tb[__VLAN_MSTP_MAX];

	int resCode = LR_SUCCESS;
	const char *pmsg =  getJsonMsg(LR_INVALID_PARAM);

	u8 mstid = 0;
	u8 portid = 0;
	u8 portState = 0;
	bool newMSTI = false;
	bool delMSTI = false;
	bool setPortState = false;
	bool flushFids = false;

	blobmsg_parse(vlan_mstp_policy, ARRAY_SIZE(vlan_mstp_policy), tb, blob_data(msg), blob_len(msg));

	if(tb[VLAN_MSTP_FLUSH_FIDS]){
		flushFids = blobmsg_get_bool(tb[VLAN_MSTP_FLUSH_FIDS]);
		if(flushFids){
			/* flush all FIDs */
			resCode = delete_all_vlan_in_vlanDatabase();
			goto process3;
		}

	}

	if(!tb[VLAN_MSTP_MSTID]){
		resCode = LR_INVALID_PARAM;
		goto returnMsg;
	}

	mstid = blobmsg_get_u8(tb[VLAN_MSTP_MSTID]);
	
	if(tb[VLAN_MSTP_NEW_MSTI]){
		newMSTI = blobmsg_get_bool(tb[VLAN_MSTP_NEW_MSTI]);
		if(newMSTI){
			/* create new msti */
			resCode = add_msti_to_hw(mstid);
			goto process2;
		}
	}

	if(tb[VLAN_MSTP_DELETE_MSTI]){
		delMSTI = blobmsg_get_bool(tb[VLAN_MSTP_DELETE_MSTI]);
		if(delMSTI){
			/* delete  msti */
			resCode = delete_msti_to_hw(mstid);
		}

	}

process2:
	if(tb[VLAN_MSTP_SET_PORT_STATE]){
		setPortState = blobmsg_get_bool(tb[VLAN_MSTP_SET_PORT_STATE]);
		if(setPortState){
			/* set port state for msti */
			if(!tb[VLAN_MSTP_PORTID] || !tb[VLAN_MSTP_PORT_STATE]){
				resCode = LR_INVALID_PARAM;
				goto returnMsg;
			}
			portid = blobmsg_get_u8(tb[VLAN_MSTP_PORTID]);
			portState = blobmsg_get_u8(tb[VLAN_MSTP_PORT_STATE]);
			resCode = set_port_state_for_msti(mstid, portid, portState);
		}

	}

process3:

	pmsg = getJsonMsg(resCode);
	

returnMsg:
	blob_buf_init(&b, 0);
	blobmsg_add_string(&b, "msg",pmsg);
	blobmsg_add_u16(&b,"resCode", resCode);

	req->deferred = false;
	ubus_send_reply(ctx, req, b.head);

	return UBUS_STATUS_OK;

}
Ejemplo n.º 30
-1
static int watchdog_set(struct ubus_context *ctx, struct ubus_object *obj,
			struct ubus_request_data *req, const char *method,
			struct blob_attr *msg)
{
	struct blob_attr *tb[__WDT_MAX];
	const char *status;

	if (!msg)
		return UBUS_STATUS_INVALID_ARGUMENT;

	blobmsg_parse(watchdog_policy, __WDT_MAX, tb, blob_data(msg), blob_len(msg));
	if (tb[WDT_FREQUENCY]) {
		unsigned int timeout = watchdog_timeout(0);
		unsigned int freq = blobmsg_get_u32(tb[WDT_FREQUENCY]);

		if (freq) {
			if (freq > timeout / 2)
				freq = timeout / 2;
			watchdog_frequency(freq);
		}
	}

	if (tb[WDT_TIMEOUT]) {
		unsigned int timeout = blobmsg_get_u32(tb[WDT_TIMEOUT]);
		unsigned int frequency = watchdog_frequency(0);

		if (timeout <= frequency)
			timeout = frequency * 2;
		 watchdog_timeout(timeout);
	}

	if (tb[WDT_STOP])
		watchdog_set_stopped(blobmsg_get_bool(tb[WDT_STOP]));

	if (watchdog_fd() == NULL)
		status = "offline";
	else if (watchdog_get_stopped())
		status = "stopped";
	else
		status = "running";

	blob_buf_init(&b, 0);
	blobmsg_add_string(&b, "status", status);
	blobmsg_add_u32(&b, "timeout", watchdog_timeout(0));
	blobmsg_add_u32(&b, "frequency", watchdog_frequency(0));
	ubus_send_reply(ctx, req, b.head);

	return 0;
}