예제 #1
1
static void mat_loop_cb(struct uloop_timeout *timeout)
{
	void *c, *t;
	char buf[16];
	int i;

	if(sys->tbus_ctx->sock.fd >= 0){
		refresh_arp_table();
		update_mat_table();

		blob_buf_init(&traffic_b, 0);
		blobmsg_add_string(&traffic_b, "hw", sys->ap_hw);
		c = blobmsg_open_array(&traffic_b, "mat");

		for (i = 0; i < arp->idx; i++) {
			t = blobmsg_open_table(&traffic_b, "arp");
			blobmsg_add_string(&traffic_b, "sta", arp->arps[i].hw);
			if(arp->arps[i].ip){
				sprintf(buf, "%u.%u.%u.%u", NIPQUAD(arp->arps[i].ip));
				blobmsg_add_string(&traffic_b, "ip", buf);
			}
			blobmsg_close_table(&traffic_b, t);
		}

		blobmsg_close_array(&traffic_b, c);
		ubus_send_event(sys->tbus_ctx, sys->cfg.tbus_listen_event, traffic_b.head);
		D(SYSTEM, "send msg and wait %d(s)\n", TRAFFICD_WIFIAP_LOOP_TIME / 1000);
	}else{
		D(SYSTEM, "ctx->sock.fd[%d]\n", sys->tbus_ctx->sock.fd);
	}
	uloop_timeout_set(timeout, TRAFFICD_WIFIAP_LOOP_TIME);
}
예제 #2
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);
	}
예제 #3
0
파일: main.c 프로젝트: OnionIoT/ogps
static int
gps_info(struct ubus_context *ctx, struct ubus_object *obj,
	struct ubus_request_data *req, const char *method,
	struct blob_attr *msg)
{
	struct timespec now;

	clock_gettime(CLOCK_MONOTONIC, &now);

	blob_buf_init(&b, 0);

	if (!stamp.tv_sec) {
		blobmsg_add_u8(&b, "signal", 0);
	} else {
		blobmsg_add_u32(&b, "age", now.tv_sec - stamp.tv_sec);
		blobmsg_add_string(&b, "latitude", latitude);
		blobmsg_add_string(&b, "longitude", longitude);
		blobmsg_add_string(&b, "elevation", elevation);
		blobmsg_add_string(&b, "course", course);
		blobmsg_add_string(&b, "speed", speed);
	}
	ubus_send_reply(ctx, req, b.head);

	return UBUS_STATUS_OK;
}
예제 #4
0
static void
cmd_nas_get_serving_system_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
{
	struct qmi_nas_get_serving_system_response res;
	static const char *reg_states[] = {
		[QMI_NAS_REGISTRATION_STATE_NOT_REGISTERED] = "not_registered",
		[QMI_NAS_REGISTRATION_STATE_REGISTERED] = "registered",
		[QMI_NAS_REGISTRATION_STATE_NOT_REGISTERED_SEARCHING] = "searching",
		[QMI_NAS_REGISTRATION_STATE_REGISTRATION_DENIED] = "registering_denied",
		[QMI_NAS_REGISTRATION_STATE_UNKNOWN] = "unknown",
	};

	qmi_parse_nas_get_serving_system_response(msg, &res);

	if (res.set.serving_system) {
		int state = res.data.serving_system.registration_state;

		if (state > QMI_NAS_REGISTRATION_STATE_UNKNOWN)
			state = QMI_NAS_REGISTRATION_STATE_UNKNOWN;

		blobmsg_add_string(&status, "registration", reg_states[state]);
	}
	if (res.set.current_plmn) {
		blobmsg_add_u32(&status, "plmn_mcc", res.data.current_plmn.mcc);
		blobmsg_add_u32(&status, "plmn_mnc", res.data.current_plmn.mnc);
		if (res.data.current_plmn.description)
			blobmsg_add_string(&status, "plmn_description", res.data.current_plmn.description);
	}

	if (res.set.roaming_indicator)
		blobmsg_add_u8(&status, "roaming", !res.data.roaming_indicator);
}
예제 #5
0
파일: igmp.c 프로젝트: itayo/juci-questd
int igmp_rpc(struct ubus_context *ctx, struct ubus_object *obj,
		struct ubus_request_data *req, const char *method,
		struct blob_attr *msg) {

	struct blob_buf bb;
	IGMPtable table[MAX_IGMP_ENTRY];
	FILE *snptable;
	char line[256];
	int idx = 0;
	void *t, *a;

	if ((snptable = fopen("/proc/net/igmp_snooping", "r"))) {
		while(fgets(line, sizeof(line), snptable) != NULL)
		{
			remove_newline(line);
			table[idx].exists = false;
			if(sscanf(single_space(line),"%s %s %s %s %x %x %x %s %x %x %x %d %x %d",
					table[idx].bridge, table[idx].device, table[idx].srcdev, table[idx].tags, &(table[idx].lantci), &(table[idx].wantci),
					&(table[idx].group), table[idx].mode, &(table[idx].RxGroup), &(table[idx].source), &(table[idx].reporter),
					&(table[idx].timeout), &(table[idx].Index), &(table[idx].ExcludPt)) == 14)
			{
				table[idx].exists = true;
				idx++;
			}
		}
		fclose(snptable);
	} else
		return UBUS_STATUS_NOT_FOUND;

	blob_buf_init(&bb, 0);

	a = blobmsg_open_array(&bb, "table");
	for (idx = 0; idx < MAX_IGMP_ENTRY; idx++) {
		if (!table[idx].exists)
			break;
		t = blobmsg_open_table(&bb, NULL);
		blobmsg_add_string(&bb,"bridge", table[idx].bridge);
		blobmsg_add_string(&bb,"device", table[idx].device);
		blobmsg_add_string(&bb,"srcdev", table[idx].srcdev);
		blobmsg_add_string(&bb,"tags", table[idx].tags);
		blobmsg_add_u32(&bb,"lantci", table[idx].lantci);
		blobmsg_add_u32(&bb,"wantci", table[idx].wantci);
		blobmsg_add_string(&bb,"group", convert_to_ipaddr(table[idx].group));
		blobmsg_add_string(&bb,"mode", table[idx].mode);
		blobmsg_add_string(&bb,"rxgroup", convert_to_ipaddr(table[idx].RxGroup));
		blobmsg_add_string(&bb,"source", convert_to_ipaddr(table[idx].source));
		blobmsg_add_string(&bb,"reporter", convert_to_ipaddr(table[idx].reporter));
		blobmsg_add_u32(&bb,"timeout", table[idx].timeout);
		blobmsg_add_u32(&bb,"index", table[idx].Index);
		blobmsg_add_u32(&bb,"excludpt", table[idx].ExcludPt);
		blobmsg_close_table(&bb, t);
	}
	blobmsg_close_array(&bb, a);

	ubus_send_reply(ctx, req, bb.head);

	return 0;
}
예제 #6
0
파일: json_script.c 프로젝트: yubo/libubox
int main(int argc, char *argv[])
{
	int i;
	char *file = NULL;
	const char *prog = argv[0];

	blobmsg_buf_init(&b_vars);
	blobmsg_buf_init(&b_script);

	json_script_init(&jctx);
	jctx.handle_command = handle_command;
	jctx.handle_file = handle_file;

	for (i = 1; i < argc; i++) {
		char *sep = strchr(argv[i], '=');
		if (sep) {
			*sep = '\0';
			blobmsg_add_string(&b_vars, argv[i], sep + 1);
		} else if (!file) {
			file = argv[i];
		} else {
			usage(prog, -1);
		}
	}
	if (i < argc || !file)
		usage(prog, -2);

	json_script_run(&jctx, file, b_vars.head);

	json_script_free(&jctx);
	blob_buf_free(&b_script);
	blob_buf_free(&b_vars);

	return 0;
}
예제 #7
0
static enum qmi_cmd_result
cmd_wds_set_auth_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
	static const struct {
		const char *name;
		QmiWdsAuthentication auth;
	} modes[] = {
		{ "pap", QMI_WDS_AUTHENTICATION_PAP },
		{ "chap", QMI_WDS_AUTHENTICATION_CHAP },
		{ "both", QMI_WDS_AUTHENTICATION_PAP | QMI_WDS_AUTHENTICATION_CHAP },
		{ "none", QMI_WDS_AUTHENTICATION_NONE },
	};
	int i;

	for (i = 0; i < ARRAY_SIZE(modes); i++) {
		if (strcasecmp(modes[i].name, arg) != 0)
			continue;

		qmi_set(&wds_sn_req, authentication_preference, modes[i].auth);
		return QMI_CMD_DONE;
	}

	blobmsg_add_string(&status, "error", "Invalid auth mode (valid: pap, chap, both, none)");
	return QMI_CMD_EXIT;
}
예제 #8
0
파일: vlan.c 프로젝트: sevennothing/lros
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;

}
예제 #9
0
파일: ubus.c 프로젝트: Cherisher/firewall3
bool
fw3_ubus_connect(void)
{
	bool status = false;
	uint32_t id;
	struct ubus_context *ctx = ubus_connect(NULL);
	struct blob_buf b = { };

	if (!ctx)
		goto out;

	if (ubus_lookup_id(ctx, "network.interface", &id))
		goto out;

	if (ubus_invoke(ctx, id, "dump", NULL, dump_cb, NULL, 2000))
		goto out;

	status = true;

	if (ubus_lookup_id(ctx, "service", &id))
		goto out;

	blob_buf_init(&b, 0);
	blobmsg_add_string(&b, "type", "firewall");
	ubus_invoke(ctx, id, "get_data", b.head, procd_data_cb, NULL, 2000);
	blob_buf_free(&b);

out:
	if (ctx)
		ubus_free(ctx);
	return status;
}
예제 #10
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;
}
예제 #11
0
static void wds_to_ipv4(const char *name, const uint32_t addr)
{
	struct in_addr ip_addr;
	char buf[INET_ADDRSTRLEN];

	ip_addr.s_addr = htonl(addr);
	blobmsg_add_string(&status, name, inet_ntop(AF_INET, &ip_addr, buf, sizeof(buf)));
}
예제 #12
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;

}
static void wds_to_ipv6(const char *name, const uint16_t *addr)
{
	char buf[INET6_ADDRSTRLEN];
	uint16_t ip_addr[8];
	int i;

	for (i = 0; i < ARRAY_SIZE(ip_addr); i++)
		ip_addr[i] = htons(addr[i]);

	blobmsg_add_string(&status, name, inet_ntop(AF_INET6, &ip_addr, buf, sizeof(buf)));
}
예제 #14
0
static void wds_to_ipv6(const char *name, const uint16_t *addr)
{
	int i;
	struct in6_addr ip_addr;
	char buf[INET6_ADDRSTRLEN];

	for (i = 0; i < ARRAY_SIZE(ip_addr.s6_addr16); i++) {
		ip_addr.s6_addr16[i] = htons(addr[i]);
	}

	blobmsg_add_string(&status, name, inet_ntop(AF_INET6, &ip_addr, buf, sizeof(buf)));
}
예제 #15
0
static void
cmd_nas_get_signal_info_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
{
	struct qmi_nas_get_signal_info_response res;

	qmi_parse_nas_get_signal_info_response(msg, &res);

	if (res.set.cdma_signal_strength) {
		blobmsg_add_string(&status, "type", "cdma");
		blobmsg_add_u32(&status, "rssi", (int32_t) res.data.cdma_signal_strength.rssi);
		blobmsg_add_u32(&status, "ecio", (int32_t) res.data.cdma_signal_strength.ecio);
	}

	if (res.set.hdr_signal_strength) {
		blobmsg_add_string(&status, "type", "hdr");
		blobmsg_add_u32(&status, "rssi", (int32_t) res.data.hdr_signal_strength.rssi);
		blobmsg_add_u32(&status, "ecio", (int32_t) res.data.hdr_signal_strength.ecio);
		blobmsg_add_u32(&status, "io", res.data.hdr_signal_strength.io);
	}

	if (res.set.gsm_signal_strength) {
		blobmsg_add_string(&status, "type", "gsm");
		blobmsg_add_u32(&status, "signal", (int32_t) res.data.gsm_signal_strength);
	}

	if (res.set.wcdma_signal_strength) {
		blobmsg_add_string(&status, "type", "wcdma");
		blobmsg_add_u32(&status, "rssi", (int32_t) res.data.wcdma_signal_strength.rssi);
		blobmsg_add_u32(&status, "ecio", (int32_t) res.data.wcdma_signal_strength.ecio);
	}

	if (res.set.lte_signal_strength) {
		blobmsg_add_string(&status, "type", "lte");
		blobmsg_add_u32(&status, "rssi", (int32_t) res.data.lte_signal_strength.rssi);
		blobmsg_add_u32(&status, "rsrq", (int32_t) res.data.lte_signal_strength.rsrq);
		blobmsg_add_u32(&status, "rsrp", (int32_t) res.data.lte_signal_strength.rsrp);
		blobmsg_add_u32(&status, "snr", (int32_t) res.data.lte_signal_strength.snr);
	}
}
예제 #16
0
void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface)
{
  struct ubus_context *ubus = (struct ubus_context *)daemon->ubus;
  int ret;

  if (!ubus || !notify)
    return;

  blob_buf_init(&b, BLOBMSG_TYPE_TABLE);
  if (mac)
    blobmsg_add_string(&b, "mac", mac);
  if (ip)
    blobmsg_add_string(&b, "ip", ip);
  if (name)
    blobmsg_add_string(&b, "name", name);
  if (interface)
    blobmsg_add_string(&b, "interface", interface);
  
  ret = ubus_notify(ubus, &ubus_object, type, b.head, -1);
  if (!ret)
    my_syslog(LOG_ERR, _("Failed to send UBus event: %s"), ubus_strerror(ret));
}
예제 #17
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;

}
예제 #18
0
파일: vlan.c 프로젝트: sevennothing/lros
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;
}
예제 #19
0
파일: commands.c 프로젝트: jing-git/rt-n56u
static enum qmi_cmd_result
cmd_ctl_set_data_format_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
	struct qmi_ctl_set_data_format_request sreq = {};
	const char *modes[] = {
		[QMI_CTL_DATA_LINK_PROTOCOL_802_3] = "802.3",
		[QMI_CTL_DATA_LINK_PROTOCOL_RAW_IP] = "raw-ip",
	};
	int mode = qmi_get_array_idx(modes, ARRAY_SIZE(modes), arg);

	if (mode < 0) {
		blobmsg_add_string(&status, "error", "Invalid mode (modes: 802.3, raw-ip)");
		return QMI_CMD_EXIT;
	}

	qmi_set_ctl_set_data_format_request(msg, &sreq);
	return QMI_CMD_DONE;
}
예제 #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;
}
예제 #21
0
static enum qmi_cmd_result
cmd_nas_set_roaming_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
	QmiNasRoamingPreference pref;

	if (!strcmp(arg, "any"))
		pref = QMI_NAS_ROAMING_PREFERENCE_ANY;
	else if (!strcmp(arg, "only"))
		pref = QMI_NAS_ROAMING_PREFERENCE_NOT_OFF;
	else if (!strcmp(arg, "off"))
		pref = QMI_NAS_ROAMING_PREFERENCE_OFF;
	else {
		blobmsg_add_string(&status, "error", "Invalid argument");
		return QMI_CMD_EXIT;
	}

	qmi_set(&sel_req, roaming_preference, pref);
	return do_sel_network();
}
예제 #22
0
파일: trace.c 프로젝트: asac/procd
static void print_syscalls(int policy, const char *json)
{
	void *c;
	int i;

	set_syscall("rt_sigaction", 1);
	set_syscall("sigreturn", 1);
	set_syscall("rt_sigreturn", 1);
	set_syscall("exit_group", 1);
	set_syscall("exit", 1);

	blob_buf_init(&b, 0);
	c = blobmsg_open_array(&b, "whitelist");

	for (i = 0; i < ARRAY_SIZE(syscall_names); i++) {
		if (!syscall_count[i])
			continue;
		if (syscall_names[i]) {
			if (debug)
				printf("syscall %d (%s) was called %d times\n",
					i, syscall_names[i], syscall_count[i]);
			blobmsg_add_string(&b, NULL, syscall_names[i]);
		} else {
			ERROR("no name found for syscall(%d)\n", i);
		}
	}
	blobmsg_close_array(&b, c);
	blobmsg_add_u32(&b, "policy", policy);
	if (json) {
		FILE *fp = fopen(json, "w");
		if (fp) {
			fprintf(fp, "%s", blobmsg_format_json_indent(b.head, true, 0));
			fclose(fp);
			INFO("saving syscall trace to %s\n", json);
		} else {
			ERROR("failed to open %s\n", json);
		}
	} else {
		printf("%s\n",
			blobmsg_format_json_indent(b.head, true, 0));
	}

}
예제 #23
0
파일: juci.c 프로젝트: schuza/juci
static int
backup_parse_list(struct blob_buf *blob, char *buf, int len, void *priv)
{
	struct backup_state *s = priv;
	char *nl = strchr(buf, '\n');

	if (!nl)
		return 0;

	if (!s->open)
	{
		s->open  = true;
		s->array = blobmsg_open_array(blob, "files");
	}

	*nl = 0;
	blobmsg_add_string(blob, NULL, buf);

	return (nl - buf + 1);
}
예제 #24
0
파일: juci.c 프로젝트: schuza/juci
static int
rpc_juci_backup_config_get(struct ubus_context *ctx, struct ubus_object *obj,
                            struct ubus_request_data *req, const char *method,
                            struct blob_attr *msg)
{
	FILE *f;
	char conf[2048] = { 0 };

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

	fread(conf, sizeof(conf) - 1, 1, f);
	fclose(f);

	blob_buf_init(&buf, 0);
	blobmsg_add_string(&buf, "config", conf);

	ubus_send_reply(ctx, req, buf.head);
	return 0;
}
예제 #25
0
static void
cmd_wds_get_packet_service_status_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg)
{
	struct qmi_wds_get_packet_service_status_response res;
	const char *data_status[] = {
		[QMI_WDS_CONNECTION_STATUS_UNKNOWN] = "unknown",
		[QMI_WDS_CONNECTION_STATUS_DISCONNECTED] = "disconnected",
		[QMI_WDS_CONNECTION_STATUS_CONNECTED] = "connected",
		[QMI_WDS_CONNECTION_STATUS_SUSPENDED] = "suspended",
		[QMI_WDS_CONNECTION_STATUS_AUTHENTICATING] = "authenticating",
	};
	int s = 0;

	qmi_parse_wds_get_packet_service_status_response(msg, &res);
	if (res.set.connection_status &&
	    res.data.connection_status < ARRAY_SIZE(data_status))
		s = res.data.connection_status;

	blobmsg_add_string(&status, NULL, data_status[s]);
}
예제 #26
0
파일: commands.c 프로젝트: jing-git/rt-n56u
static bool __uqmi_run_commands(struct qmi_dev *qmi, bool option)
{
	static char buf[2048];
	static struct qmi_request req;
	int i;

	for (i = 0; i < n_cmds; i++) {
		enum qmi_cmd_result res;
		bool cmd_option = cmds[i].handler->type == CMD_TYPE_OPTION;
		bool do_break = false;

		if (cmd_option != option)
			continue;

		blob_buf_init(&status, 0);
		if (cmds[i].handler->type > QMI_SERVICE_CTL &&
		    qmi_service_connect(qmi, cmds[i].handler->type, -1)) {
			blobmsg_printf(&status, "error", "failed to connect to service");
			res = QMI_CMD_EXIT;
		} else {
			res = cmds[i].handler->prepare(qmi, &req, (void *) buf, cmds[i].arg);
		}

		if (res == QMI_CMD_REQUEST) {
			qmi_request_start(qmi, &req, (void *) buf, cmds[i].handler->cb);
			req.no_error_cb = true;
			if (qmi_request_wait(qmi, &req)) {
				blobmsg_add_string(&status, "error", qmi_get_error_str(req.ret));
				do_break = true;
			}
		} else if (res == QMI_CMD_EXIT) {
			do_break = true;
		}

		uqmi_print_result(status.head);
		if (do_break)
			return false;
	}
	return true;
}
예제 #27
0
static enum qmi_cmd_result
cmd_nas_set_network_modes_prepare(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg, char *arg)
{
	static const struct {
		const char *name;
		QmiNasRatModePreference val;
	} modes[] = {
		{ "cdma", QMI_NAS_RAT_MODE_PREFERENCE_CDMA_1X | QMI_NAS_RAT_MODE_PREFERENCE_CDMA_1XEVDO },
		{ "td-scdma", QMI_NAS_RAT_MODE_PREFERENCE_TD_SCDMA },
		{ "gsm", QMI_NAS_RAT_MODE_PREFERENCE_GSM },
		{ "umts", QMI_NAS_RAT_MODE_PREFERENCE_UMTS },
		{ "lte", QMI_NAS_RAT_MODE_PREFERENCE_LTE },
	};
	QmiNasRatModePreference val = 0;
	char *word;
	int i;

	for (word = strtok(arg, ",");
	     word;
	     word = strtok(NULL, ",")) {
		bool found = false;

		for (i = 0; i < ARRAY_SIZE(modes); i++) {
			if (strcmp(word, modes[i].name) != 0 &&
				strcmp(word, "all") != 0)
				continue;

			val |= modes[i].val;
			found = true;
		}

		if (!found) {
			blobmsg_add_string(&status, "error", "Invalid network mode");
			return QMI_CMD_EXIT;
		}
	}

	qmi_set(&sel_req, mode_preference, val);
	return do_sel_network();
}
예제 #28
0
파일: proc.c 프로젝트: darcyg/juci-uhttpd
static void proc_handle_header(struct relay *r, const char *name, const char *val)
{
	static char status_buf[64];
	struct client *cl = r->cl;
	char *sep;
	char buf[4];

	if (!strcmp(name, "Status")) {
		sep = strchr(val, ' ');
		if (sep != val + 3)
			return;

		memcpy(buf, val, 3);
		buf[3] = 0;
		snprintf(status_buf, sizeof(status_buf), "%s", sep + 1);
		cl->dispatch.proc.status_msg = status_buf;
		cl->dispatch.proc.status_code = atoi(buf);
		return;
	}

	blobmsg_add_string(&cl->dispatch.proc.hdr, name, val);
}
예제 #29
0
static int client_ubus_process(char *ubus_object, char *ubus_method, char *argv)
{
  static struct ubus_request req;
  uint32_t id;
  int ret, ret_ubus_invoke;
  const char *ubus_socket = NULL;
  struct ubus_context *ctx_local;

  ctx_local = ubus_connect(ubus_socket);
  if (!ctx_local) {
    printf("Failed to connect to ubus\n");
    return -1;
  }

  if (ubus_lookup_id(ctx_local, ubus_object, &id)) {
    printf("Failed to look up test object\n");
    return -1;
  }

  blob_buf_init(&b_local, 0);

  blobmsg_add_string(&b_local, "cmd", argv);

  ret_ubus_invoke = ubus_invoke(ctx_local, id, ubus_method, b_local.head, receive_call_result_data, 0, 20000);
 
  if(ret_ubus_invoke == 0 || ret_ubus_invoke == 7)
  {
    ret = 0;
  }
  else
  {
    ret = -1;
  }

  ubus_free(ctx_local);
  return ret;
}
예제 #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;
}