unsigned int nf_bridge_encap_header_len(const struct sk_buff *skb) { switch (skb->protocol) { case __cpu_to_be16(ETH_P_8021Q): return VLAN_HLEN; case __cpu_to_be16(ETH_P_PPP_SES): return PPPOE_SES_HLEN; default: return 0; } }
static int sipc4_netif_rx(struct net_device *dev, struct sk_buff *skb, int res) { struct phonethdr *ph; int err; skb->protocol = htons(ETH_P_PHONET); ph = (struct phonethdr *)skb_push(skb, sizeof(struct phonethdr)); ph->pn_rdev = dev->dev_addr[0]; ph->pn_sdev = 0; ph->pn_res = res; ph->pn_length = __cpu_to_be16(skb->len + 2 - sizeof(*ph)); ph->pn_robj = 0; ph->pn_sobj = 0; skb->dev = dev; dev->stats.rx_packets++; dev->stats.rx_bytes += skb->len; skb_reset_mac_header(skb); err = netif_rx(skb); if (err != NET_RX_SUCCESS) dev_err(&dev->dev, "rx error: %d\n", err); return err; }
int tea5764_i2c_write(struct tea5764_device *radio) { struct tea5764_write_regs wr; struct tea5764_regs *r = &radio->regs; struct i2c_msg msgs[1] = { { radio->i2c_client->addr, 0, sizeof(wr), (void *) &wr }, }; wr.intreg = r->intreg & 0xff; wr.frqset = __cpu_to_be16(r->frqset); wr.tnctrl = __cpu_to_be16(r->tnctrl); wr.testreg = __cpu_to_be16(r->testreg); wr.rdsctrl = __cpu_to_be16(r->rdsctrl); wr.rdsbbl = __cpu_to_be16(r->rdsbbl); if (i2c_transfer(radio->i2c_client->adapter, msgs, 1) != 1) return -EIO; return 0; }
/* * Prepends an ISI header and sends a datagram. */ static int pn_send(struct sk_buff *skb, struct net_device *dev, u16 dst, u16 src, u8 res, u8 irq) { struct phonethdr *ph; int err; if (skb->len + 2 > 0xffff /* Phonet length field limit */ || skb->len + sizeof(struct phonethdr) > dev->mtu) { err = -EMSGSIZE; goto drop; } /* Broadcast sending is not implemented */ if (pn_addr(dst) == PNADDR_BROADCAST) { err = -EOPNOTSUPP; goto drop; } skb_reset_transport_header(skb); WARN_ON(skb_headroom(skb) & 1); /* HW assumes word alignment */ skb_push(skb, sizeof(struct phonethdr)); skb_reset_network_header(skb); ph = pn_hdr(skb); ph->pn_rdev = pn_dev(dst); ph->pn_sdev = pn_dev(src); ph->pn_res = res; ph->pn_length = __cpu_to_be16(skb->len + 2 - sizeof(*ph)); ph->pn_robj = pn_obj(dst); ph->pn_sobj = pn_obj(src); skb->protocol = htons(ETH_P_PHONET); skb->priority = 0; skb->dev = dev; if (pn_addr(src) == pn_addr(dst)) { skb_reset_mac_header(skb); skb->pkt_type = PACKET_LOOPBACK; skb_orphan(skb); if (irq) netif_rx(skb); else netif_rx_ni(skb); err = 0; } else { err = dev_hard_header(skb, dev, ntohs(skb->protocol), NULL, NULL, skb->len); if (err < 0) { err = -EHOSTUNREACH; goto drop; } err = dev_queue_xmit(skb); } return err; drop: kfree_skb(skb); return err; }
int Packet::BuildPacket(BYTE btAddr, BYTE btCmd, WORD wRegAddr, WORD wRegAddrCount, void *pData, BYTE btLen) { m_btAddr = btAddr; m_btCmd = btCmd; *(WORD *)&m_Data[0] = __cpu_to_be16(wRegAddr); *(WORD *)&m_Data[2] = __cpu_to_be16(wRegAddrCount); int nPacketLen = 6; // copy data if (pData != NULL) { m_Data[4] = btLen; memcpy(&m_Data[5], pData, btLen); nPacketLen += (btLen+1); } // checksum *(WORD *)(&m_btAddr+nPacketLen) = __cpu_to_le16(CheckSUM(&m_btAddr, nPacketLen)); nPacketLen += 2; // return all packet length return nPacketLen; }
static void write_val16(__u16 *adr, __u16 val) { switch(endian) { case ENDIAN_HOST: *adr = val; break; case ENDIAN_LITTLE: *adr = __cpu_to_le16(val); break; case ENDIAN_BIG: *adr = __cpu_to_be16(val); break; } }
static int sipc4_netif_rx(struct net_device *dev, struct sk_buff *skb, int res) { struct phonethdr *ph; int err; skb->protocol = htons(ETH_P_PHONET); ph = (struct phonethdr *)skb_push(skb, sizeof(struct phonethdr)); ph->pn_rdev = dev->dev_addr[0]; ph->pn_sdev = 0; ph->pn_res = res; ph->pn_length = __cpu_to_be16(skb->len + 2 - sizeof(*ph)); ph->pn_robj = 0; ph->pn_sobj = 0; skb->dev = dev; dev->stats.rx_packets++; dev->stats.rx_bytes += skb->len; skb_reset_mac_header(skb); #if 0 int i; char str[1024]; int len = 0; int maxlen = skb->len > 256 ? 256 : skb->len; printk(KERN_INFO "[SIPC] size: %d\n", skb->len); for (i = 0 ; i < maxlen ; i++) len += sprintf(str + len, "%02x ", skb->data[i]); if (maxlen != 256) sprintf(str + len, "\n"); else sprintf(str + len, "...\n"); printk(KERN_INFO "%s", str); #endif err = netif_rx(skb); if (err != NET_RX_SUCCESS) dev_err(&dev->dev, "rx error: %d\n", err); return err; }
/* * si470x_set_register - write register */ int si470x_set_register(struct si470x_device *radio, int regnr) { int i; u16 buf[WRITE_REG_NUM]; struct i2c_msg msgs[1] = { { radio->client->addr, 0, sizeof(u16) * WRITE_REG_NUM, (void *)buf }, }; for (i = 0; i < WRITE_REG_NUM; i++) buf[i] = __cpu_to_be16(radio->registers[WRITE_INDEX(i)]); if (i2c_transfer(radio->client->adapter, msgs, 1) != 1) return -EIO; return 0; }
static int aoehdr_atainit(struct aoedev *d, struct aoe_hdr *h) { u16 type = __constant_cpu_to_be16(ETH_P_AOE); u16 aoemajor = __cpu_to_be16(d->aoemajor); u32 host_tag = newtag(d); u32 tag = __cpu_to_be32(host_tag); memcpy(h->src, d->ifp->dev_addr, sizeof h->src); memcpy(h->dst, d->addr, sizeof h->dst); memcpy(h->type, &type, sizeof type); h->verfl = AOE_HVER; memcpy(h->major, &aoemajor, sizeof aoemajor); h->minor = d->aoeminor; h->cmd = AOECMD_ATA; memcpy(h->tag, &tag, sizeof tag); return host_tag; }
const void *build_llc_header(size_t *len) { struct llc_header *header = NULL; const void *buf = NULL; buf = malloc(sizeof(struct llc_header)); if(buf) { *len = sizeof(struct llc_header); memset((void *) buf, 0, sizeof(struct llc_header)); header = (struct llc_header *) buf; header->dsap = LLC_SNAP; header->ssap = LLC_SNAP; header->control_field = UNNUMBERED_FRAME; header->type = __cpu_to_be16(DOT1X_AUTHENTICATION); } return buf; }
/* returns 1 if this was a spectral frame, even if not handled. */ int ath_process_fft(struct ath_softc *sc, struct ieee80211_hdr *hdr, struct ath_rx_status *rs, u64 tsf) { struct ath_hw *ah = sc->sc_ah; u8 num_bins, *bins, *vdata = (u8 *)hdr; struct fft_sample_ht20 fft_sample_20; struct fft_sample_ht20_40 fft_sample_40; struct fft_sample_tlv *tlv; struct ath_radar_info *radar_info; int len = rs->rs_datalen; int dc_pos; u16 fft_len, length, freq = ah->curchan->chan->center_freq; enum nl80211_channel_type chan_type; /* AR9280 and before report via ATH9K_PHYERR_RADAR, AR93xx and newer * via ATH9K_PHYERR_SPECTRAL. Haven't seen ATH9K_PHYERR_FALSE_RADAR_EXT * yet, but this is supposed to be possible as well. */ if (rs->rs_phyerr != ATH9K_PHYERR_RADAR && rs->rs_phyerr != ATH9K_PHYERR_FALSE_RADAR_EXT && rs->rs_phyerr != ATH9K_PHYERR_SPECTRAL) return 0; /* check if spectral scan bit is set. This does not have to be checked * if received through a SPECTRAL phy error, but shouldn't hurt. */ radar_info = ((struct ath_radar_info *)&vdata[len]) - 1; if (!(radar_info->pulse_bw_info & SPECTRAL_SCAN_BITMASK)) return 0; chan_type = cfg80211_get_chandef_type(&sc->hw->conf.chandef); if ((chan_type == NL80211_CHAN_HT40MINUS) || (chan_type == NL80211_CHAN_HT40PLUS)) { fft_len = SPECTRAL_HT20_40_TOTAL_DATA_LEN; num_bins = SPECTRAL_HT20_40_NUM_BINS; bins = (u8 *)fft_sample_40.data; } else { fft_len = SPECTRAL_HT20_TOTAL_DATA_LEN; num_bins = SPECTRAL_HT20_NUM_BINS; bins = (u8 *)fft_sample_20.data; } /* Variation in the data length is possible and will be fixed later */ if ((len > fft_len + 2) || (len < fft_len - 1)) return 1; switch (len - fft_len) { case 0: /* length correct, nothing to do. */ memcpy(bins, vdata, num_bins); break; case -1: /* first byte missing, duplicate it. */ memcpy(&bins[1], vdata, num_bins - 1); bins[0] = vdata[0]; break; case 2: /* MAC added 2 extra bytes at bin 30 and 32, remove them. */ memcpy(bins, vdata, 30); bins[30] = vdata[31]; memcpy(&bins[31], &vdata[33], num_bins - 31); break; case 1: /* MAC added 2 extra bytes AND first byte is missing. */ bins[0] = vdata[0]; memcpy(&bins[1], vdata, 30); bins[31] = vdata[31]; memcpy(&bins[32], &vdata[33], num_bins - 32); break; default: return 1; } /* DC value (value in the middle) is the blind spot of the spectral * sample and invalid, interpolate it. */ dc_pos = num_bins / 2; bins[dc_pos] = (bins[dc_pos + 1] + bins[dc_pos - 1]) / 2; if ((chan_type == NL80211_CHAN_HT40MINUS) || (chan_type == NL80211_CHAN_HT40PLUS)) { s8 lower_rssi, upper_rssi; s16 ext_nf; u8 lower_max_index, upper_max_index; u8 lower_bitmap_w, upper_bitmap_w; u16 lower_mag, upper_mag; struct ath9k_hw_cal_data *caldata = ah->caldata; struct ath_ht20_40_mag_info *mag_info; if (caldata) ext_nf = ath9k_hw_getchan_noise(ah, ah->curchan, caldata->nfCalHist[3].privNF); else ext_nf = ATH_DEFAULT_NOISE_FLOOR; length = sizeof(fft_sample_40) - sizeof(struct fft_sample_tlv); fft_sample_40.tlv.type = ATH_FFT_SAMPLE_HT20_40; fft_sample_40.tlv.length = __cpu_to_be16(length); fft_sample_40.freq = __cpu_to_be16(freq); fft_sample_40.channel_type = chan_type; if (chan_type == NL80211_CHAN_HT40PLUS) { lower_rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]); upper_rssi = fix_rssi_inv_only(rs->rs_rssi_ext[0]); fft_sample_40.lower_noise = ah->noise; fft_sample_40.upper_noise = ext_nf; } else { lower_rssi = fix_rssi_inv_only(rs->rs_rssi_ext[0]); upper_rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]); fft_sample_40.lower_noise = ext_nf; fft_sample_40.upper_noise = ah->noise; } fft_sample_40.lower_rssi = lower_rssi; fft_sample_40.upper_rssi = upper_rssi; mag_info = ((struct ath_ht20_40_mag_info *)radar_info) - 1; lower_mag = spectral_max_magnitude(mag_info->lower_bins); upper_mag = spectral_max_magnitude(mag_info->upper_bins); fft_sample_40.lower_max_magnitude = __cpu_to_be16(lower_mag); fft_sample_40.upper_max_magnitude = __cpu_to_be16(upper_mag); lower_max_index = spectral_max_index(mag_info->lower_bins); upper_max_index = spectral_max_index(mag_info->upper_bins); fft_sample_40.lower_max_index = lower_max_index; fft_sample_40.upper_max_index = upper_max_index; lower_bitmap_w = spectral_bitmap_weight(mag_info->lower_bins); upper_bitmap_w = spectral_bitmap_weight(mag_info->upper_bins); fft_sample_40.lower_bitmap_weight = lower_bitmap_w; fft_sample_40.upper_bitmap_weight = upper_bitmap_w; fft_sample_40.max_exp = mag_info->max_exp & 0xf; fft_sample_40.tsf = __cpu_to_be64(tsf); tlv = (struct fft_sample_tlv *)&fft_sample_40; } else { u8 max_index, bitmap_w; u16 magnitude; struct ath_ht20_mag_info *mag_info; length = sizeof(fft_sample_20) - sizeof(struct fft_sample_tlv); fft_sample_20.tlv.type = ATH_FFT_SAMPLE_HT20; fft_sample_20.tlv.length = __cpu_to_be16(length); fft_sample_20.freq = __cpu_to_be16(freq); fft_sample_20.rssi = fix_rssi_inv_only(rs->rs_rssi_ctl[0]); fft_sample_20.noise = ah->noise; mag_info = ((struct ath_ht20_mag_info *)radar_info) - 1; magnitude = spectral_max_magnitude(mag_info->all_bins); fft_sample_20.max_magnitude = __cpu_to_be16(magnitude); max_index = spectral_max_index(mag_info->all_bins); fft_sample_20.max_index = max_index; bitmap_w = spectral_bitmap_weight(mag_info->all_bins); fft_sample_20.bitmap_weight = bitmap_w; fft_sample_20.max_exp = mag_info->max_exp & 0xf; fft_sample_20.tsf = __cpu_to_be64(tsf); tlv = (struct fft_sample_tlv *)&fft_sample_20; } ath_debug_send_fft_sample(sc, tlv); return 1; }
/* * Flattened Device Tree command, see the help for parameter definitions. */ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) { char op; if (argc < 2) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } /* * Figure out which subcommand was given */ op = argv[1][0]; /******************************************************************** * Set the address of the fdt ********************************************************************/ if (op == 'a') { /* * Set the address [and length] of the fdt. */ fdt = (struct fdt_header *)simple_strtoul(argv[2], NULL, 16); if (!fdt_valid()) { return 1; } if (argc >= 4) { int len; int err; /* * Optional new length */ len = simple_strtoul(argv[3], NULL, 16); if (len < fdt_totalsize(fdt)) { printf ("New length %d < existing length %d, ignoring.\n", len, fdt_totalsize(fdt)); } else { /* * Open in place with a new length. */ err = fdt_open_into(fdt, fdt, len); if (err != 0) { printf ("libfdt: %s\n", fdt_strerror(err)); } } } /******************************************************************** * Move the fdt ********************************************************************/ } else if (op == 'm' && argv[1][1] == 'o') { struct fdt_header *newaddr; int len; int err; if (argc != 5) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } /* * Set the address and length of the fdt. */ fdt = (struct fdt_header *)simple_strtoul(argv[2], NULL, 16); if (!fdt_valid()) { return 1; } newaddr = (struct fdt_header *)simple_strtoul(argv[3], NULL, 16); len = simple_strtoul(argv[4], NULL, 16); if (len < fdt_totalsize(fdt)) { printf ("New length %d < existing length %d, aborting.\n", len, fdt_totalsize(fdt)); return 1; } /* * Copy to the new location. */ err = fdt_open_into(fdt, newaddr, len); if (err != 0) { printf ("libfdt: %s\n", fdt_strerror(err)); return 1; } fdt = newaddr; /******************************************************************** * mknode ********************************************************************/ } else if (op == 'm' && argv[1][1] == 'k') { char *pathp = argv[2]; char *node = argv[3]; int nodeoffset; if (argc != 4) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } /* * See if the node already exists */ if (strcmp(pathp, "/") == 0) nodeoffset = 0; else nodeoffset = fdt_path_offset (fdt, pathp); if (nodeoffset < 0) { printf("parent node %s doesn't exist\n", pathp); return 1; } /* * Create the new node */ nodeoffset = fdt_add_subnode(fdt, nodeoffset, node); if (nodeoffset < 0) { printf("libfdt: %s\n", fdt_strerror(nodeoffset)); return 1; } /******************************************************************** * Set the value of a node in the fdt. ********************************************************************/ } else if (op == 's') { char *pathp; /* path */ char *prop; /* property */ struct fdt_property *nodep; /* node struct pointer */ char *newval; /* value from the user (as a string) */ char *vp; /* temporary value pointer */ char *cp; /* temporary char pointer */ int nodeoffset; /* node offset from libfdt */ int len; /* new length of the property */ int oldlen; /* original length of the property */ unsigned long tmp; /* holds converted values */ int ret; /* return value */ /* * Parameters: Node path, property, value. */ if (argc < 5) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } pathp = argv[2]; prop = argv[3]; newval = argv[4]; if (strcmp(pathp, "/") == 0) { nodeoffset = 0; } else { nodeoffset = fdt_path_offset (fdt, pathp); if (nodeoffset < 0) { /* * Not found or something else bad happened. */ printf ("libfdt: %s\n", fdt_strerror(nodeoffset)); return 1; } } nodep = fdt_getprop (fdt, nodeoffset, prop, &oldlen); if (oldlen == 0) { /* * The specified property has no value */ printf("%s has no value, cannot set one (yet).\n", prop); return 1; } else { /* * Convert the new property */ vp = data; if (*newval == '<') { /* * Bigger values than bytes. */ len = 0; newval++; while ((*newval != '>') && (*newval != '\0')) { cp = newval; tmp = simple_strtoul(cp, &newval, 16); if ((newval - cp) <= 2) { *vp = tmp & 0xFF; vp += 1; len += 1; } else if ((newval - cp) <= 4) { *(uint16_t *)vp = __cpu_to_be16(tmp); vp += 2; len += 2; } else if ((newval - cp) <= 8) { *(uint32_t *)vp = __cpu_to_be32(tmp); vp += 4; len += 4; } else { printf("Sorry, I could not convert \"%s\"\n", cp); return 1; } while (*newval == ' ') newval++; } if (*newval != '>') { printf("Unexpected character '%c'\n", *newval); return 1; } } else if (*newval == '[') { /* * Byte stream. Convert the values. */ len = 0; newval++; while ((*newval != ']') && (*newval != '\0')) { tmp = simple_strtoul(newval, &newval, 16); *vp++ = tmp & 0xFF; len++; while (*newval == ' ') newval++; } if (*newval != ']') { printf("Unexpected character '%c'\n", *newval); return 1; } } else { /* * Assume it is a string. Copy it into our data area for * convenience (including the terminating '\0'). */ len = strlen(newval) + 1; strcpy(data, newval); } ret = fdt_setprop(fdt, nodeoffset, prop, data, len); if (ret < 0) { printf ("libfdt %s\n", fdt_strerror(ret)); return 1; } } /******************************************************************** * Print (recursive) / List (single level) ********************************************************************/ } else if ((op == 'p') || (op == 'l')) { /* * Recursively print (a portion of) the fdt. */ static int offstack[MAX_LEVEL]; static char tabs[MAX_LEVEL+1] = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; int depth = MAX_LEVEL; /* how deep to print */ char *pathp; /* path */ char *prop; /* property */ void *nodep; /* property node pointer */ int nodeoffset; /* node offset from libfdt */ int nextoffset; /* next node offset from libfdt */ uint32_t tag; /* tag */ int len; /* length of the property */ int level = 0; /* keep track of nesting level */ /* * list is an alias for print, but limited to 1 level */ if (op == 'l') { depth = 1; } /* * Get the starting path. The root node is an oddball, * the offset is zero and has no name. */ pathp = argv[2]; if (argc > 3) prop = argv[3]; else prop = NULL; if (strcmp(pathp, "/") == 0) { nodeoffset = 0; printf("/"); } else { nodeoffset = fdt_path_offset (fdt, pathp); if (nodeoffset < 0) { /* * Not found or something else bad happened. */ printf ("libfdt %s\n", fdt_strerror(nodeoffset)); return 1; } } /* * The user passed in a property as well as node path. Print only * the given property and then return. */ if (prop) { nodep = fdt_getprop (fdt, nodeoffset, prop, &len); if (len == 0) { printf("%s %s\n", pathp, prop); /* no property value */ return 0; } else if (len > 0) { printf("%s=", prop); print_data (nodep, len); printf("\n"); return 0; } else { printf ("libfdt %s\n", fdt_strerror(len)); return 1; } } /* * The user passed in a node path and no property, print the node * and all subnodes. */ offstack[0] = nodeoffset; while(level >= 0) { tag = fdt_next_tag(fdt, nodeoffset, &nextoffset, &pathp); switch(tag) { case FDT_BEGIN_NODE: if(level <= depth) printf("%s%s {\n", &tabs[MAX_LEVEL - level], pathp); level++; offstack[level] = nodeoffset; if (level >= MAX_LEVEL) { printf("Aaaiii <splat> nested too deep.\n"); return 1; } break; case FDT_END_NODE: level--; if(level <= depth) printf("%s};\n", &tabs[MAX_LEVEL - level]); if (level == 0) { level = -1; /* exit the loop */ } break; case FDT_PROP: nodep = fdt_getprop (fdt, offstack[level], pathp, &len); if (len < 0) { printf ("libfdt %s\n", fdt_strerror(len)); return 1; } else if (len == 0) { /* the property has no value */ if(level <= depth) printf("%s%s;\n", &tabs[MAX_LEVEL - level], pathp); } else { if(level <= depth) { printf("%s%s=", &tabs[MAX_LEVEL - level], pathp); print_data (nodep, len); printf(";\n"); } } break; case FDT_NOP: break; case FDT_END: return 1; default: if(level <= depth) printf("Unknown tag 0x%08X\n", tag); return 1; } nodeoffset = nextoffset; } /******************************************************************** * Remove a property/node ********************************************************************/ } else if (op == 'r') { int nodeoffset; /* node offset from libfdt */ int err; /* * Get the path. The root node is an oddball, the offset * is zero and has no name. */ if (strcmp(argv[2], "/") == 0) { nodeoffset = 0; } else { nodeoffset = fdt_path_offset (fdt, argv[2]); if (nodeoffset < 0) { /* * Not found or something else bad happened. */ printf ("libfdt %s\n", fdt_strerror(nodeoffset)); return 1; } } /* * Do the delete. A fourth parameter means delete a property, * otherwise delete the node. */ if (argc > 3) { err = fdt_delprop(fdt, nodeoffset, argv[3]); if (err < 0) { printf("fdt_delprop libfdt: %s\n", fdt_strerror(err)); return err; } } else { err = fdt_del_node(fdt, nodeoffset); if (err < 0) { printf("fdt_del_node libfdt: %s\n", fdt_strerror(err)); return err; } } /******************************************************************** * Create a chosen node ********************************************************************/ } else if (op == 'c') { fdt_chosen(fdt, 0, 0, 1); #ifdef CONFIG_OF_HAS_UBOOT_ENV /******************************************************************** * Create a u-boot-env node ********************************************************************/ } else if (op == 'e') { fdt_env(fdt); #endif #ifdef CONFIG_OF_HAS_BD_T /******************************************************************** * Create a bd_t node ********************************************************************/ } else if (op == 'b') { fdt_bd_t(fdt); #endif /******************************************************************** * Unrecognized command ********************************************************************/ } else { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } return 0; }
/* This function writes a chunks of data. A data chunk consists of a raw inode, perhaps a name and perhaps some data. */ void write_file(struct jffs_file *f, FILE *fs, struct stat st) { int npad = JFFS_GET_PAD_BYTES(f->inode.nsize); int dpad = JFFS_GET_PAD_BYTES(read_val32(&f->inode.dsize)); int size = sizeof(struct jffs_raw_inode) + f->inode.nsize + npad + read_val32(&f->inode.dsize) + dpad; unsigned char ff_data[] = { 0xff, 0xff, 0xff, 0xff }; if (verbose >= 2) { fprintf(stderr, "***write_file()\n"); } /* Write the raw inode. */ fwrite((void *)&f->inode, sizeof(struct jffs_raw_inode), 1, fs); /* Write the name. */ if (f->inode.nsize) { fwrite(f->name, 1, f->inode.nsize, fs); if (npad) { fwrite(ff_data, 1, npad, fs); } } /* Write the data. */ if (read_val32(&f->inode.dsize)) { if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode)) { __u16 tmp; switch(endian) { case ENDIAN_HOST: tmp = st.st_rdev; break; case ENDIAN_LITTLE: tmp = __cpu_to_le16(st.st_rdev); break; case ENDIAN_BIG: tmp = __cpu_to_be16(st.st_rdev); break; } fwrite((char *)&tmp, sizeof(st.st_rdev) / 4, 1, fs); } else { fwrite(f->data, 1, read_val32(&f->inode.dsize), fs); } if (dpad) { fwrite(ff_data, 1, dpad, fs); } } fs_pos += size; /* If the space left on the block is smaller than the size of an inode, then skip it. */ }
u16 htons(u16 hostshort) { return __cpu_to_be16(hostshort); }
/* * Prepends an ISI header and sends a datagram. */ static int pn_send(struct sk_buff *skb, struct net_device *dev, u16 dst, u16 src, u8 res, u8 irq) { struct phonethdr *ph; int err, i; if (skb->len + 2 > 0xffff /* Phonet length field limit */ || skb->len + sizeof(struct phonethdr) > dev->mtu) { err = -EMSGSIZE; goto drop; } /* Broadcast sending is not implemented */ if (pn_addr(dst) == PNADDR_BROADCAST) { err = -EOPNOTSUPP; goto drop; } skb_reset_transport_header(skb); WARN_ON(skb_headroom(skb) & 1); /* HW assumes word alignment */ skb_push(skb, sizeof(struct phonethdr)); skb_reset_network_header(skb); ph = pn_hdr(skb); ph->pn_rdev = pn_dev(dst); ph->pn_sdev = pn_dev(src); ph->pn_res = res; ph->pn_length = __cpu_to_be16(skb->len + 2 - sizeof(*ph)); ph->pn_robj = pn_obj(dst); ph->pn_sobj = pn_obj(src); skb->protocol = htons(ETH_P_PHONET); skb->priority = 0; skb->dev = dev; PN_PRINTK("pn_send rdev %x sdev %x res %x robj %x sobj %x netdev=%s\n", ph->pn_rdev, ph->pn_sdev, ph->pn_res, ph->pn_robj, ph->pn_sobj, dev->name); PN_DATA_PRINTK("PHONET : skb data = %d\nPHONET :", skb->len); for (i = 1; i <= skb->len; i++) { PN_DATA_PRINTK(" %02x", skb->data[i-1]); if ((i%8) == 0) PN_DATA_PRINTK("\n"); } if (skb->pkt_type == PACKET_LOOPBACK) { skb_reset_mac_header(skb); skb_orphan(skb); err = (irq ? netif_rx(skb) : netif_rx_ni(skb)) ? -ENOBUFS : 0; } else { err = dev_hard_header(skb, dev, ntohs(skb->protocol), NULL, NULL, skb->len); if (err < 0) { err = -EHOSTUNREACH; goto drop; } err = dev_queue_xmit(skb); if (unlikely(err > 0)) err = net_xmit_errno(err); } return err; drop: printk(KERN_DEBUG "pn_send DROP\n"); kfree_skb(skb); return err; }
/* * Parse the user's input, partially heuristic. Valid formats: * <00> - hex byte * <0011> - hex half word (16 bits) * <00112233> - hex word (32 bits) * - hex double words (64 bits) are not supported, must use * a byte stream instead. * [00 11 22 .. nn] - byte stream * "string" - If the the value doesn't start with "<" or "[", it is * treated as a string. Note that the quotes are * stripped by the parser before we get the string. */ static int fdt_parse_prop(char *pathp, char *prop, char *newval, char *data, int *len) { char *cp; /* temporary char pointer */ unsigned long tmp; /* holds converted values */ if (*newval == '<') { /* * Bigger values than bytes. */ *len = 0; newval++; while ((*newval != '>') && (*newval != '\0')) { cp = newval; tmp = simple_strtoul(cp, &newval, 16); if ((newval - cp) <= 2) { *data = tmp & 0xFF; data += 1; *len += 1; } else if ((newval - cp) <= 4) { *(uint16_t *)data = __cpu_to_be16(tmp); data += 2; *len += 2; } else if ((newval - cp) <= 8) { *(uint32_t *)data = __cpu_to_be32(tmp); data += 4; *len += 4; } else { printf("Sorry, I could not convert \"%s\"\n", cp); return 1; } while (*newval == ' ') newval++; } if (*newval != '>') { printf("Unexpected character '%c'\n", *newval); return 1; } } else if (*newval == '[') { /* * Byte stream. Convert the values. */ *len = 0; newval++; while ((*newval != ']') && (*newval != '\0')) { tmp = simple_strtoul(newval, &newval, 16); *data++ = tmp & 0xFF; *len = *len + 1; while (*newval == ' ') newval++; } if (*newval != ']') { printf("Unexpected character '%c'\n", *newval); return 1; } } else { /* * Assume it is a string. Copy it into our data area for * convenience (including the terminating '\0'). */ *len = strlen(newval) + 1; strcpy(data, newval); } return 0; }