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); }
static void put_container(struct blob_buf *buf, struct blob_attr *attr, const char *name) { void *c = blobmsg_open_table(buf, name); blob_put_raw(buf, blob_data(attr), blob_len(attr)); blobmsg_close_table(buf, c); }
static bool menu_access(struct blob_attr *sid, struct blob_attr *acls, struct blob_buf *e) { int rem; struct blob_attr *acl; bool rv = true; void *c; c = blobmsg_open_table(e, "write"); blobmsg_for_each_attr(acl, acls, rem) { if (!ops->session_access(blobmsg_data(sid), "access-group", blobmsg_data(acl), "read")) { rv = false; break; } blobmsg_add_u8(e, blobmsg_data(acl), ops->session_access(blobmsg_data(sid), "access-group", blobmsg_data(acl), "write")); } blobmsg_close_table(e, c); return rv; }
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; }
static int system_info(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { void *c; time_t now; struct tm *tm; struct sysinfo info; now = time(NULL); if (!(tm = localtime(&now))) return UBUS_STATUS_UNKNOWN_ERROR; if (sysinfo(&info)) return UBUS_STATUS_UNKNOWN_ERROR; blob_buf_init(&b, 0); blobmsg_add_u32(&b, "uptime", info.uptime); blobmsg_add_u32(&b, "localtime", mktime(tm)); c = blobmsg_open_array(&b, "load"); blobmsg_add_u32(&b, NULL, info.loads[0]); blobmsg_add_u32(&b, NULL, info.loads[1]); blobmsg_add_u32(&b, NULL, info.loads[2]); blobmsg_close_array(&b, c); c = blobmsg_open_table(&b, "memory"); blobmsg_add_u64(&b, "total", info.mem_unit * info.totalram); blobmsg_add_u64(&b, "free", info.mem_unit * info.freeram); blobmsg_add_u64(&b, "shared", info.mem_unit * info.sharedram); blobmsg_add_u64(&b, "buffered", info.mem_unit * info.bufferram); blobmsg_close_table(&b, c); c = blobmsg_open_table(&b, "swap"); blobmsg_add_u64(&b, "total", info.mem_unit * info.totalswap); blobmsg_add_u64(&b, "free", info.mem_unit * info.freeswap); blobmsg_close_table(&b, c); ubus_send_reply(ctx, req, b.head); return UBUS_STATUS_OK; }
static void ubus_push_method_data(const struct ubus_method *m) { void *mtbl; int i; mtbl = blobmsg_open_table(&b, m->name); for (i = 0; i < m->n_policy; i++) { if (m->mask && !(m->mask & (1 << i))) continue; blobmsg_add_u32(&b, m->policy[i].name, m->policy[i].type); } blobmsg_close_table(&b, mtbl); }
static void cmd_wds_get_current_settings_cb(struct qmi_dev *qmi, struct qmi_request *req, struct qmi_msg *msg) { void *v4, *v6, *d, *t; struct qmi_wds_get_current_settings_response res; const char *pdptypes[] = { [QMI_WDS_PDP_TYPE_IPV4] = "ipv4", [QMI_WDS_PDP_TYPE_PPP] = "ppp", [QMI_WDS_PDP_TYPE_IPV6] = "ipv6", [QMI_WDS_PDP_TYPE_IPV4_OR_IPV6] = "ipv4-or-ipv6", }; const struct ip_modes { const char *name; const QmiWdsIpFamily mode; } modes[] = { { "ipv4", QMI_WDS_IP_FAMILY_IPV4 }, { "ipv6", QMI_WDS_IP_FAMILY_IPV6 }, { "unspecified", QMI_WDS_IP_FAMILY_UNSPECIFIED }, }; int i; qmi_parse_wds_get_current_settings_response(msg, &res); t = blobmsg_open_table(&status, NULL); if (res.set.pdp_type && res.data.pdp_type < ARRAY_SIZE(pdptypes)) blobmsg_add_string(&status, "pdp-type", pdptypes[res.data.pdp_type]); if (res.set.ip_family) { for (i = 0; i < ARRAY_SIZE(modes); i++) { if (modes[i].mode != res.data.ip_family) continue; blobmsg_add_string(&status, "ip-family", modes[i].name); break; } } if (res.set.mtu) blobmsg_add_u32(&status, "mtu", res.data.mtu); /* IPV4 */ v4 = blobmsg_open_table(&status, "ipv4"); if (res.set.ipv4_address) wds_to_ipv4("ip", res.data.ipv4_address); if (res.set.primary_ipv4_dns_address) wds_to_ipv4("dns1", res.data.primary_ipv4_dns_address); if (res.set.secondary_ipv4_dns_address) wds_to_ipv4("dns2", res.data.secondary_ipv4_dns_address); if (res.set.ipv4_gateway_address) wds_to_ipv4("gateway", res.data.ipv4_gateway_address); if (res.set.ipv4_gateway_subnet_mask) wds_to_ipv4("subnet", res.data.ipv4_gateway_subnet_mask); blobmsg_close_table(&status, v4); /* IPV6 */ v6 = blobmsg_open_table(&status, "ipv6"); if (res.set.ipv6_address) { wds_to_ipv6("ip", res.data.ipv6_address.address); blobmsg_add_u32(&status, "ip-prefix-length", res.data.ipv6_address.prefix_length); } if (res.set.ipv6_gateway_address) { wds_to_ipv6("gateway", res.data.ipv6_gateway_address.address); blobmsg_add_u32(&status, "gw-prefix-length", res.data.ipv6_gateway_address.prefix_length); } if (res.set.ipv6_primary_dns_address) wds_to_ipv6("dns1", res.data.ipv6_primary_dns_address); if (res.set.ipv6_secondary_dns_address) wds_to_ipv6("dns2", res.data.ipv6_secondary_dns_address); blobmsg_close_table(&status, v6); d = blobmsg_open_table(&status, "domain-names"); for (i = 0; i < res.data.domain_name_list_n; i++) { blobmsg_add_string(&status, NULL, res.data.domain_name_list[i]); } blobmsg_close_table(&status, d); blobmsg_close_table(&status, t); }