static int parse_ip6_class(int *argc_p, char ***argv_p, struct tc_u32_sel *sel) { int res = -1; int argc = *argc_p; char **argv = *argv_p; __u32 key; __u32 mask; int off = 0; int offmask = 0; if (argc < 2) return -1; if (get_u32(&key, *argv, 0)) return -1; argc--; argv++; if (get_u32(&mask, *argv, 16)) return -1; argc--; argv++; if (key > 0xFF || mask > 0xFF) return -1; key <<= 20; mask <<= 20; key = htonl(key); mask = htonl(mask); res = pack_key(sel, key, mask, off, offmask); if (res < 0) return -1; *argc_p = argc; *argv_p = argv; return 0; }
static int qfq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) { struct rtattr *tail; __u32 tmp; tail = NLMSG_TAIL(n); addattr_l(n, 4096, TCA_OPTIONS, NULL, 0); while (argc > 0) { if (matches(*argv, "weight") == 0) { NEXT_ARG(); if (get_u32(&tmp, *argv, 10)) { explain1("weight"); return -1; } addattr32(n, 4096, TCA_QFQ_WEIGHT, tmp); } else if (matches(*argv, "maxpkt") == 0) { NEXT_ARG(); if (get_u32(&tmp, *argv, 10)) { explain1("maxpkt"); return -1; } addattr32(n, 4096, TCA_QFQ_LMAX, tmp); } else if (strcmp(*argv, "help") == 0) { explain_class(); return -1; } else { fprintf(stderr, "What is \"%s\"?\n", *argv); explain_class(); return -1; } argc--; argv++; } tail->rta_len = (void *)NLMSG_TAIL(n) - (void *)tail; return 0; }
static int labx_local_audio_of_probe(struct of_device *ofdev, const struct of_device_id *match) { struct resource r_mem_struct; struct resource *addressRange = &r_mem_struct; struct platform_device *pdev = to_platform_device(&ofdev->dev); const char *interfaceType; u32 numChannels; int ret; u32 has_serializer; /* Obtain the resources for this instance; use the device tree node name */ const char *name = ofdev->node->name; ret = of_address_to_resource(ofdev->node, 0, addressRange); if (ret) { dev_warn(&ofdev->dev, "Invalid address\n"); return(ret); } /* Look up the number of channels in the device tree */ numChannels = (get_u32(ofdev, "xlnx,num-i2s-streams") * 2); /* Check the interface type to see if a DMA exists */ has_serializer = get_u32(ofdev, "xlnx,has-serializer"); if (has_serializer) interfaceType = (char *) of_get_property(ofdev->node, "xlnx,interface-type", NULL); else interfaceType = LA_DMA_INTERFACE_EXTERNAL; if(interfaceType == NULL) { dev_warn(&ofdev->dev, "labx_local_audio : (%s) No interface type defined\n", name); return(-1); } /* Dispatch to the generic function */ return(labx_local_audio_probe(name, pdev, addressRange, interfaceType, numChannels, NULL, NULL, NULL)); }
static int xfrm_seq_parse(__u32 *seq, int *argcp, char ***argvp) { int argc = *argcp; char **argv = *argvp; if (get_u32(seq, *argv, 0)) invarg("\"SEQ\" is invalid", *argv); *seq = htonl(*seq); *argcp = argc; *argvp = argv; return 0; }
static int ccnsfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) { int ok=0; struct tc_ccnsfq_qopt opt; memset(&opt, 0, sizeof(opt)); while (argc > 0) { if (strcmp(*argv, "quantum") == 0) { NEXT_ARG(); if (get_size(&opt.quantum, *argv)) { fprintf(stderr, "Illegal \"limit\"\n"); return -1; } ok++; } else if (strcmp(*argv, "perturb") == 0) { NEXT_ARG(); if (get_integer(&opt.perturb_period, *argv, 0)) { fprintf(stderr, "Illegal \"perturb\"\n"); return -1; } ok++; } else if (strcmp(*argv, "limit") == 0) { NEXT_ARG(); if (get_u32(&opt.limit, *argv, 0)) { fprintf(stderr, "Illegal \"limit\"\n"); return -1; } if (opt.limit < 2) { fprintf(stderr, "Illegal \"limit\", must be > 1\n"); return -1; } ok++; } else if (strcmp(*argv, "help") == 0) { explain(); return -1; } else { fprintf(stderr, "What is \"%s\"?\n", *argv); explain(); return -1; } argc--; argv++; } if (ok) addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt)); return 0; }
int do_seg6(int argc, char **argv) { if (argc < 1 || matches(*argv, "help") == 0) usage(); memset(&opts, 0, sizeof(opts)); if (matches(*argv, "hmac") == 0) { NEXT_ARG(); if (matches(*argv, "show") == 0) { opts.cmd = SEG6_CMD_DUMPHMAC; } else if (matches(*argv, "set") == 0) { NEXT_ARG(); if (get_u32(&opts.keyid, *argv, 0) || opts.keyid == 0) invarg("hmac KEYID value is invalid", *argv); NEXT_ARG(); if (strcmp(*argv, "sha1") == 0) { opts.alg_id = SEG6_HMAC_ALGO_SHA1; } else if (strcmp(*argv, "sha256") == 0) { opts.alg_id = SEG6_HMAC_ALGO_SHA256; } else { invarg("hmac ALGO value is invalid", *argv); } opts.cmd = SEG6_CMD_SETHMAC; opts.pass = getpass(HMAC_KEY_PROMPT); } else { invarg("unknown", *argv); } } else if (matches(*argv, "tunsrc") == 0) { NEXT_ARG(); if (matches(*argv, "show") == 0) { opts.cmd = SEG6_CMD_GET_TUNSRC; } else if (matches(*argv, "set") == 0) { NEXT_ARG(); opts.cmd = SEG6_CMD_SET_TUNSRC; if (!inet_get_addr(*argv, NULL, &opts.addr)) invarg("tunsrc ADDRESS value is invalid", *argv); } else { invarg("unknown", *argv); } } else { invarg("unknown", *argv); } return seg6_do_cmd(); }
int get_u32_handle(__u32 *handle, char *str) { __u32 htid=0, hash=0, nodeid=0; char *tmp = strchr(str, ':'); if (tmp == NULL) { if (memcmp("0x", str, 2) == 0) return get_u32(handle, str, 16); return -1; } htid = strtoul(str, &tmp, 16); if (tmp == str && *str != ':' && *str != 0) return -1; //if (htid>=0x1000) // return -1; //if (htid>=0xFFFF) // return -1; if (htid>=0x1000)//richie1124 return -1; if (*tmp) { str = tmp+1; hash = strtoul(str, &tmp, 16); fprintf(stderr, "1 get_u32_handle: hash[%x]\n",hash); if (tmp == str && *str != ':' && *str != 0) return -1; //if (hash>=0x100)//richie1124 // return -1; if (hash>=0x1000) return -1; if (*tmp) { str = tmp+1; nodeid = strtoul(str, &tmp, 16); if (tmp == str && *str != 0) return -1; //if (nodeid>=0x1000)//richie1124 // return -1; if (nodeid>=0x100) return -1; } } //fprintf(stderr, "get_u32_handle: htid[%x], hash[%x], nodeid[%x]\n",htid, hash, nodeid); //*handle = (htid<<20)|(hash<<12)|nodeid; //*handle = (htid<<16)|(hash<<8)|nodeid; *handle = (htid<<20)|(hash<<8)|nodeid;//richie1124 return 0; }
static int ssh_request_reply(AuthenticationConnection *auth, Buffer *request, Buffer *reply) { u_int l, len; char buf[1024]; /* Get the length of the message, and format it in the buffer. */ len = buffer_len(request); put_u32(buf, len); /* Send the length and then the packet to the agent. */ if (atomicio(vwrite, auth->fd, buf, 4) != 4 || atomicio(vwrite, auth->fd, buffer_ptr(request), buffer_len(request)) != buffer_len(request)) { error("Error writing to authentication socket."); return 0; } /* * Wait for response from the agent. First read the length of the * response packet. */ if (atomicio(read, auth->fd, buf, 4) != 4) { error("Error reading response length from authentication socket."); return 0; } /* Extract the length, and check it for sanity. */ len = get_u32(buf); if (len > 256 * 1024) fatal("Authentication response too long: %u", len); /* Read the rest of the response in to the buffer. */ buffer_clear(reply); while (len > 0) { l = len; if (l > sizeof(buf)) l = sizeof(buf); if (atomicio(read, auth->fd, buf, l) != l) { error("Error reading response from authentication socket."); return 0; } buffer_append(reply, buf, l); len -= l; } return 1; }
static int parse_val(int *argc_p, char ***argv_p, __u32 *val, int type) { int argc = *argc_p; char **argv = *argv_p; if (argc <= 0) return -1; if (type == TINT) return get_integer((int *)val, *argv, 0); if (type == TU32) return get_u32(val, *argv, 0); if (type == TIPV4) { inet_prefix addr; if (get_prefix_1(&addr, *argv, AF_INET)) return -1; *val = addr.data[0]; return 0; } if (type == TIPV6) { inet_prefix addr; if (get_prefix_1(&addr, *argv, AF_INET6)) return -1; memcpy(val, addr.data, addr.bytelen); return 0; } if (type == TMAC) { #define MAC_ALEN 6 int ret = ll_addr_a2n((char *)val, MAC_ALEN, *argv); if (ret == MAC_ALEN) return 0; } return -1; }
static int parse_nofopt(struct filter_util *qu, char *fhandle, int argc, char **argv, struct nlmsghdr *n) { __u32 handle; if (argc) { fprintf(stderr, "Unknown filter \"%s\", hence option \"%s\" is unparsable\n", qu->id, *argv); return -1; } if (fhandle) { struct tcmsg *t = NLMSG_DATA(n); if (get_u32(&handle, fhandle, 16)) { fprintf(stderr, "Unparsable filter ID \"%s\"\n", fhandle); return -1; } t->tcm_handle = handle; } return 0; }
static int aice_pipe_read_debug_reg(uint32_t coreid, uint32_t addr, uint32_t *val) { char line[AICE_PIPE_MAXLINE]; char command[AICE_PIPE_MAXLINE]; command[0] = AICE_READ_DEBUG_REG; set_u32(command + 1, addr); if (aice_pipe_write(command, 5) != 5) return ERROR_FAIL; if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0) return ERROR_FAIL; *val = get_u32(line); return ERROR_OK; }
void ipoque_search_socrates(struct ipoque_detection_module_struct *ipoque_struct) { struct ipoque_packet_struct *packet = &ipoque_struct->packet; struct ipoque_flow_struct *flow = ipoque_struct->flow; // struct ipoque_id_struct *src=ipoque_struct->src; // struct ipoque_id_struct *dst=ipoque_struct->dst; IPQ_LOG(IPOQUE_PROTOCOL_SOCRATES, ipoque_struct, IPQ_LOG_DEBUG, "search socrates.\n"); if (packet->udp != NULL) { if (packet->payload_packet_len > 9 && packet->payload[0] == 0xfe && packet->payload[packet->payload_packet_len - 1] == 0x05) { IPQ_LOG(IPOQUE_PROTOCOL_SOCRATES, ipoque_struct, IPQ_LOG_DEBUG, "found fe.\n"); IPQ_LOG(IPOQUE_PROTOCOL_SOCRATES, ipoque_struct, IPQ_LOG_DEBUG, "len match.\n"); if (memcmp(&packet->payload[2], "socrates", 8) == 0) { IPQ_LOG(IPOQUE_PROTOCOL_SOCRATES, ipoque_struct, IPQ_LOG_DEBUG, "found socrates udp.\n"); ipoque_socrates_add_connection(ipoque_struct); } } } else if (packet->tcp != NULL) { if (packet->payload_packet_len > 13 && packet->payload[0] == 0xfe && packet->payload[packet->payload_packet_len - 1] == 0x05) { IPQ_LOG(IPOQUE_PROTOCOL_SOCRATES, ipoque_struct, IPQ_LOG_DEBUG, "found fe.\n"); if (packet->payload_packet_len == ntohl(get_u32(packet->payload, 2))) { IPQ_LOG(IPOQUE_PROTOCOL_SOCRATES, ipoque_struct, IPQ_LOG_DEBUG, "len match.\n"); if (memcmp(&packet->payload[6], "socrates", 8) == 0) { IPQ_LOG(IPOQUE_PROTOCOL_SOCRATES, ipoque_struct, IPQ_LOG_DEBUG, "found socrates tcp.\n"); ipoque_socrates_add_connection(ipoque_struct); } } } } IPQ_LOG(IPOQUE_PROTOCOL_SOCRATES, ipoque_struct, IPQ_LOG_DEBUG, "exclude socrates.\n"); IPOQUE_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, IPOQUE_PROTOCOL_SOCRATES); }
__init int routerboot_find_magic(u8 *buf, unsigned int buflen, u32 *offset, bool hard) { u32 magic_ref = hard ? RB_MAGIC_HARD : RB_MAGIC_SOFT; u32 magic; u32 cur = *offset; while (cur < buflen) { magic = get_u32(buf + cur); if (magic == magic_ref) { *offset = cur; return 0; } cur += 0x1000; } return -ENOENT; }
u_int8_t check_dhcp(dpi_library_state_t* state, dpi_pkt_infos_t* pkt, const unsigned char* app_data, u_int32_t data_length, dpi_tracking_informations_t* t){ if(data_length >= 244 && /** Minimum data_length. **/ /** Ports check. **/ ((pkt->srcport==port_dhcp_1 && pkt->dstport==port_dhcp_2) || (pkt->dstport==port_dhcp_1 && pkt->srcport==port_dhcp_2)) && /** Magic cookie. **/ get_u32(app_data, 236)==DPI_DHCP_MAGIC_COOKIE && /** * First two bytes of DHCP message type. * Are the same for any DHCP message type. **/ get_u16(app_data, 240)==DPI_DHCP_TYPE){ return DPI_PROTOCOL_MATCHES; }else{ return DPI_PROTOCOL_NO_MATCHES; } }
static bool is_utf32 (const uint8_t *data, size_t n, uint32_t (*get_u32) (const uint8_t *)) { if (n < ENCODING_GUESS_MIN && n % 4 != 0) return false; while (n >= 4) { uint32_t uc = get_u32 (data); if (uc < 0x09 || uc > 0x10ffff) return false; data += 4; n -= 4; } return true; }
/* Communicate with agent: send request and read reply */ static int ssh_request_reply(int sock, struct sshbuf *request, struct sshbuf *reply) { int r; size_t l, len; char buf[1024]; /* Get the length of the message, and format it in the buffer. */ len = sshbuf_len(request); put_u32(buf, len); /* Send the length and then the packet to the agent. */ if (atomicio(vwrite, sock, buf, 4) != 4 || atomicio(vwrite, sock, (u_char *)sshbuf_ptr(request), sshbuf_len(request)) != sshbuf_len(request)) return SSH_ERR_AGENT_COMMUNICATION; /* * Wait for response from the agent. First read the length of the * response packet. */ if (atomicio(read, sock, buf, 4) != 4) return SSH_ERR_AGENT_COMMUNICATION; /* Extract the length, and check it for sanity. */ len = get_u32(buf); if (len > MAX_AGENT_REPLY_LEN) return SSH_ERR_INVALID_FORMAT; /* Read the rest of the response in to the buffer. */ sshbuf_reset(reply); while (len > 0) { l = len; if (l > sizeof(buf)) l = sizeof(buf); if (atomicio(read, sock, buf, l) != l) return SSH_ERR_AGENT_COMMUNICATION; if ((r = sshbuf_put(reply, buf, l)) != 0) return r; len -= l; } return 0; }
void bpa_dump(int level, struct frame *frm) { uint8_t id, status, channel; uint16_t num, len; uint32_t time; id = get_u8(frm); num = get_u16(frm); len = BPA_U16(frm); status = get_u8(frm); time = get_u32(frm); channel = get_u8(frm); p_indent(level, frm); printf("BPA: id %d num %d len %u status 0x%02x time %d channel %d\n", id, num, len, status, time, channel); raw_dump(level, frm); }
int do_cmd_turbo(int fd, char *state) { int r; int turbo_on = atoi(state); if(0 == strcasecmp("ON", state)) { turbo_on = 1; } r = send_cmd_turbo(fd, turbo_on); if(r < 0) { return -EPROTO; } r = get_tf_packet(fd, &reply); if(r < 0) { return -EPROTO; } switch (get_u32(&reply.cmd)) { case SUCCESS: trace(1, fprintf(stderr, "Turbo mode: %s\n", turbo_on ? "ON" : "OFF")); return 0; break; case FAIL: fprintf(stderr, "ERROR: Device reports %s\n", decode_error(&reply)); break; default: fprintf(stderr, "ERROR: Unhandled packet\n"); } return -EPROTO; }
int get_sauce(FILE *fp, sauce_t *out) { long cur_pos; cur_pos = ftell(fp); if (fseek(fp, -128, SEEK_END) == -1) return -1; /* * can't count on Sauce structure to be char aligned, * so this bit reads it piecemeal. Hate to add all these * numbers without #defines, but they're in sauce.h if it * really is confusing. */ fread(out->id, 1, 5, fp); fread(out->version, 1, 2, fp); fread(out->title, 1, 35, fp); fread(out->author, 1, 20, fp); fread(out->group, 1, 20, fp); fread(out->date, 1, 8, fp); get_u32(&out->file_size, fp); fread(&out->data_type, 1, 1, fp); fread(&out->file_type, 1, 1, fp); get_u16(&out->t_info1, fp); get_u16(&out->t_info2, fp); get_u16(&out->t_info3, fp); get_u16(&out->t_info4, fp); fread(&out->comments, 1, 1, fp); fread(&out->flags, 1, 1, fp); fseek(fp, cur_pos, SEEK_SET); if (strncmp(out->id, "SAUCE", 5) == 0) return 0; return -1; }
void mm_request_receive(int sock, Buffer *m) { u_char buf[4]; u_int msg_len; debug3("%s entering", __func__); if (atomicio(read, sock, buf, sizeof(buf)) != sizeof(buf)) { if (errno == EPIPE) cleanup_exit(255); fatal("%s: read: %s", __func__, strerror(errno)); } msg_len = get_u32(buf); if (msg_len > 256 * 1024) fatal("%s: read: bad msg_len %d", __func__, msg_len); buffer_clear(m); buffer_append_space(m, msg_len); if (atomicio(read, sock, buffer_ptr(m), msg_len) != msg_len) fatal("%s: read: %s", __func__, strerror(errno)); }
static int aice_pipe_read_tlb(uint32_t coreid, uint32_t virtual_address, uint32_t *physical_address) { char line[AICE_PIPE_MAXLINE]; char command[AICE_PIPE_MAXLINE]; command[0] = AICE_READ_TLB; set_u32(command + 1, virtual_address); if (aice_pipe_write(command, 5) != 5) return ERROR_FAIL; if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0) return ERROR_FAIL; if (line[0] == AICE_OK) { *physical_address = get_u32(line + 1); return ERROR_OK; } else return ERROR_FAIL; }
int packet_fxp_open(Buffer *buff, Buffer *preped_buff) { u_int msg_len; u_int xmsg_len; // File names u_int file_len, pflags; u_char *filename; // Copy first part of packet over to prepared buffer msg_len = get_u32(buffer_ptr(buff)); xmsg_len = msg_len; buffer_append(preped_buff, buffer_ptr(buff), 9); buffer_consume(buff, 9); xmsg_len -= 5; // Rewrite path filename = buffer_get_string(buff, &file_len); filename = unchroot_filename(filename, (u_char*) user_homedir); buffer_put_cstring(preped_buff, (char*) filename); xmsg_len -= (file_len + 4); msg_len += (strlen((char*) filename) - file_len); // pflags pflags = buffer_get_int(buff); buffer_put_int(preped_buff, pflags); xmsg_len -= 4; // Copy attributes through, cleaning extensions where required parse_attrs(buff, preped_buff, &msg_len, &xmsg_len); // Copy any remaining packet data over buffer_append(preped_buff, buffer_ptr(buff), xmsg_len); buffer_consume(buff, xmsg_len); // Rewrite message length put_u32(buffer_end(preped_buff)-msg_len-4, msg_len); return 1; }
int tree_search_next(struct tree_search *ts, unsigned char **p, int dir) { struct tree_search_node *tsn=&ts->nodes[ts->curr_node]; if (! *p) *p=tsn->p; dbg(1,"next *p=%p dir=%d\n", *p, dir); dbg(1,"low1=0x%x high1=0x%x\n", tsn->low, tsn->high); if (dir <= 0) { dbg(1,"down 0x%x\n", tsn->low); if (tsn->low != 0xffffffff) { tsn=tree_search_enter(ts, tsn->low); *p=tsn->p; tsn->high=get_u32(p); ts->last_node=ts->curr_node; dbg(1,"saving last2 %d 0x%x\n", ts->curr_node, tsn->last-ts->f->begin); dbg(1,"high2=0x%x\n", tsn->high); return 0; } return -1; } tsn->low=tsn->high; tsn->last=*p; tsn->high=get_u32_unal(p); dbg(1,"saving last3 %d %p\n", ts->curr_node, tsn->last); if (*p < tsn->end) return (tsn->low == 0xffffffff ? 1 : 0); dbg(1,"end reached high=0x%x\n",tsn->high); if (tsn->low != 0xffffffff) { dbg(1,"low 0x%x\n", tsn->low); tsn=tree_search_enter(ts, tsn->low); *p=tsn->p; tsn->high=get_u32_unal(p); ts->last_node=ts->curr_node; dbg(1,"saving last4 %d 0x%x\n", ts->curr_node, tsn->last-ts->f->begin); dbg(1,"high4=0x%x\n", tsn->high); return 0; } return -1; }
inline static char * get_address_tlv_value(char *msg_ptr, struct tlv_tuple_local *tuple) { tuple->value = 0; tuple->multi_value = NULL; tuple->extended_value = NULL; switch (tuple->length) { case sizeof(olsr_u8_t): { olsr_u8_t v; msg_ptr = get_u8(msg_ptr, &v); tuple->value = v; } break; case sizeof(olsr_u16_t): { olsr_u16_t v; msg_ptr = get_u16(msg_ptr, &v); tuple->value = v; } break; case sizeof(olsr_u32_t): { olsr_u32_t v; msg_ptr = get_u32(msg_ptr, &v); tuple->value = v; } break; default: tuple->extended_value = (olsr_u8_t *)olsr_malloc(tuple->length, __FUNCTION__); memcpy(tuple->extended_value, msg_ptr, tuple->length); msg_ptr += tuple->length; } return msg_ptr; }
int packet_fxp_symlink(Buffer *buff, Buffer *preped_buff) { u_int msg_len; u_int xmsg_len; // File names u_int file_len; u_char *filename; // Copy first part of packet over to prepared buffer msg_len = get_u32(buffer_ptr(buff)); xmsg_len = msg_len; buffer_append(preped_buff, buffer_ptr(buff), 9); buffer_consume(buff, 9); xmsg_len -= 5; // Rewrite link path filename = buffer_get_string(buff, &file_len); filename = unchroot_filename(filename, (u_char*) user_homedir); buffer_put_cstring(preped_buff, (char*) filename); xmsg_len -= (file_len + 4); msg_len += (strlen((char*) filename) - file_len); // Rewrite target path filename = buffer_get_string(buff, &file_len); filename = unchroot_filename(filename, (u_char*) user_homedir); buffer_put_cstring(preped_buff, (char*) filename); xmsg_len -= (file_len + 4); msg_len += (strlen((char*) filename) - file_len); // Copy any remaining packet data over buffer_append(preped_buff, buffer_ptr(buff), xmsg_len); buffer_consume(buff, xmsg_len); // Rewrite message length put_u32(buffer_end(preped_buff)-msg_len-4, msg_len); return 1; }
/*Search for BitTorrent commands*/ int search_bittorrent (const unsigned char *payload, const u16 plen) { if (plen > 20) { /* test for match 0x13+"BitTorrent protocol" */ if (*payload == 0x13) { if (memcmp(payload+1, "BitTorrent protocol", 19) == 0) return (IPP2P_BIT * 100); } /* get tracker commandos, all starts with GET / * then it can follow: scrape| announce * and then ?hash_info= */ if (memcmp(payload,"GET /",5) == 0) { /* message scrape */ if ( memcmp(payload+5,"scrape?info_hash=",17)==0 ) return (IPP2P_BIT * 100 + 1); /* message announce */ if ( memcmp(payload+5,"announce",8)==0 ) return (IPP2P_BIT * 100 + 2); if ( memcmp(payload+5,"?info_hash=",11)==0 ) return (IPP2P_BIT * 100 + 3); if ( memcmp(payload+5,"data?fid=",9)==0 ) return (IPP2P_BIT * 100 + 5); } } else { /* bitcomet encryptes the first packet, so we have to detect another * one later in the flow */ /* first try failed, too many missdetections */ //if ( size == 5 && get_u32(t,0) == __constant_htonl(1) && t[4] < 3) return (IPP2P_BIT * 100 + 3); /* second try: block request packets */ if ( plen == 17 && get_u32(payload,0) == __constant_htonl(0x0d) && *(payload+4) == 0x06 && get_u32(payload,13) == __constant_htonl(0x4000) ) return (IPP2P_BIT * 100 + 4); } return 0; }
static int labx_audio_meters_of_probe(struct of_device *ofdev, const struct of_device_id *match) { struct resource r_mem_struct; struct resource *addressRange = &r_mem_struct; struct platform_device *pdev = to_platform_device(&ofdev->dev); u32 numChannels; int ret; u32 has_serializer; /* Obtain the resources for this instance; use the device tree node name */ const char *name = ofdev->node->name; ret = of_address_to_resource(ofdev->node, 0, addressRange); if (ret) { dev_warn(&ofdev->dev, "Invalid address\n"); return(ret); } /* Look up the number of channels in the device tree */ numChannels = (1 << get_u32(ofdev, "xlnx,channel-addr-width")); /* Dispatch to the generic function */ return(labx_audio_meters_probe(name, pdev, addressRange, numChannels)); }
static int aice_pipe_idcode(uint32_t *idcode, uint8_t *num_of_idcode) { char line[AICE_PIPE_MAXLINE]; char command[AICE_PIPE_MAXLINE]; command[0] = AICE_IDCODE; if (aice_pipe_write(command, 1) != 1) return ERROR_FAIL; if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0) return ERROR_FAIL; *num_of_idcode = line[0]; if ((*num_of_idcode == 0) || (*num_of_idcode >= 16)) return ERROR_FAIL; for (int i = 0 ; i < *num_of_idcode ; i++) idcode[i] = get_u32(line + i * 4 + 1); return ERROR_OK; }
static uint_8 const *GetInt( uint_8 const *p, uint_32 *ret, int size ) /********************************************************************/ { switch( size ) { case 0: *ret = 0; break; case 1: *ret = *p; break; case 2: *ret = get_u16( (uint_16 *)p ); break; case 4: *ret = get_u32( (uint_32 *)p ); break; default: *ret = 0xffffffff; break; } p += size; return( p ); }
static int get_info_func (CameraFilesystem *fs, const char *folder, const char *filename, CameraFileInfo *info, void *data, GPContext *context) { Camera *camera = data; int r; struct tf_packet reply; char *xfolder = strdup (folder); backslash (xfolder); r = send_cmd_hdd_dir(camera, xfolder, context); free (xfolder); if(r < GP_OK) return r; while(0 < get_tf_packet(camera, &reply, context)) { switch (get_u32(&reply.cmd)) { case DATA_HDD_DIR: decode_and_get_info(camera, folder, &reply, filename, info, context); send_success(camera,context); break; case DATA_HDD_DIR_END: return GP_OK; break; case FAIL: gp_log (GP_LOG_ERROR, "topfield", "ERROR: Device reports %s\n", decode_error(&reply)); return GP_ERROR_IO; break; default: gp_log (GP_LOG_ERROR, "topfield", "ERROR: Unhandled packet\n"); return GP_ERROR_IO; } } return GP_OK; }