static int32_t fswrite(Usbfs *fs, Fid *fid, void *data, int32_t count, int64_t) { int cn, qt; char buf[128]; Buf *bp; Conn *c; Ether *e; Qid q; q = fid->qid; q.path &= ~fs->qid; e = fs->aux; qt = qtype(q.path); cn = qnum(q.path); switch(qt){ case Qndata: c = getconn(e, cn, 0); if(c == nil){ werrstr(Eio); return -1; } bp = allocbuf(e); if(count > sizeof(bp->data)-Hdrsize) count = sizeof(bp->data)-Hdrsize; memmove(bp->rp, data, count); bp->ndata = count; if(etherdebug > 1) dumpframe("etherout", bp->rp, bp->ndata); if(e->nblock == 0) sendp(e->wc, bp); else if(nbsendp(e->wc, bp) == 0){ deprint(2, "%s: (out) packet lost\n", argv0); e->noerrs++; freebuf(e, bp); } break; case Qnctl: c = getconn(e, cn, 0); if(c == nil){ werrstr(Eio); return -1; } if(count > sizeof(buf) - 1) count = sizeof(buf) - 1; memmove(buf, data, count); buf[count] = 0; if(etherctl(e, c, buf) < 0) return -1; break; default: sysfatal("usb: ether: fsread bug"); } return count; }
int tr2eth(struct packed_ether_header *frame) { struct trh_hdr hdr; struct trllc *pllc; int hlen = 0; #ifdef DEBUG dumpframe("tr2eth: Incoming tr frame", frame); #endif hdr = *((struct trh_hdr *)frame); if (hdr.saddr[0] & TR_RII) { fake_rif : hlen = hdr.rcf & ntohs(TR_RCF_LEN_MASK); #ifdef DEBUG printf("rcf = 0x%X SR len %d\n", hdr.rcf, hlen); #endif if (hlen < sizeof(hdr.rcf) || (hlen & 1)) return 1; hdr.saddr[0] &= ~TR_RII; } pllc = (struct trllc *)(((__u8 *)frame) + sizeof(struct trh_hdr) - TR_MAXRIFLEN + hlen); if (pllc->dsap != EXTENDED_SAP || pllc->llc != UI_CMD) { if (hlen == 0) goto fake_rif; /* Bug in 2.2.3 kernel */ #ifdef DEBUG printf("corrupted TR-IP packet of ui=0x%x and dsap 0x%x discarded\n", pllc->llc,pllc->dsap); #endif return 1; } memcpy(frame->ether_dhost, hdr.daddr, ETH_ALEN); memcpy(frame->ether_shost, hdr.saddr, ETH_ALEN); frame->ether_type = pllc->ethertype; memmove(frame + 1, pllc + 1, IPPACKET_SIZE); /* Move data portion: Overlapping buffer */ #ifdef DEBUG dumpframe("tr2eth: Outgoing eth frame", frame); #endif return 0; }
/***** convert ethernet and token-ring frames *****/ int eth2tr(struct packed_ether_header *frame, int datalen) { struct trh_hdr *phdr; struct trllc *pllc; char trheader[sizeof(struct trh_hdr) - sizeof(phdr->rseg) + sizeof(struct trllc)]; int len; #ifdef DEBUG dumpframe("eth2tr: Incoming eth frame", frame); #endif memset(trheader, 0, sizeof(trheader)); phdr = (struct trh_hdr *)trheader; phdr->ac = AC; phdr->fc = LLC_FRAME; memcpy(phdr->daddr, frame->ether_dhost, TR_ALEN); memcpy(phdr->saddr, frame->ether_shost, TR_ALEN); if (phdr->daddr[0] & 0x80) { /* Destination is a broadcast */ phdr->rcf = sizeof(phdr->rcf) | htons(TR_RCF_BROADCAST | 0x70); /* Unlimited frame length */ pllc = (struct trllc *)&phdr->rseg[0]; phdr->saddr[0] |= TR_RII; /* Set source-route indicator */ len = sizeof(trheader); } else { pllc = (struct trllc *)&phdr->rcf; len = sizeof(trheader) - sizeof(phdr->rcf); } pllc->dsap = EXTENDED_SAP; pllc->ssap = EXTENDED_SAP; pllc->llc = UI_CMD; pllc->protid[0] = pllc->protid[1] = pllc->protid[2] = 0; pllc->ethertype = frame->ether_type; memmove((char *)(frame + 1) + (len - sizeof(struct packed_ether_header)), frame + 1, datalen); /* Make room for larger TR header */ memcpy(frame, trheader, len); /* Install TR header */ #ifdef DEBUG dumpframe("eth2tr: Outgoing tr frame", frame); #endif return len + datalen; }
void ofxMocha::loadFromText (string filename) { frames.clear(); FILE * pFile; pFile = fopen (filename.c_str() , "r"); if (pFile == NULL) return; vector<frame>::iterator iter; int num; bool res; char line [100]; char str [100]; while (!feof(pFile)) { fgets (line , 100 , pFile); cout << line ; if (sscanf(line, "%s",str) != 1) { continue; } if (strcmp(str,"Position") == 0) { fgets (line , 100 , pFile); cout << line ; fgets (line , 100 , pFile); frame f; clearframe(f); while (sscanf(line, "%u %f %f %f",&f.num,&f.x,&f.y,&f.z) == 4) { frames.push_back(f); dumpframe(&f); clearframe(f); fgets (line , 100 , pFile); } } else if (strcmp(str,"Scale") == 0) { fgets (line , 100 , pFile); cout << line ; fgets (line , 100 , pFile); iter = frames.begin(); while (sscanf(line, "%u %f %f %f",&num,&(iter->scaleX),&(iter->scaleY),&(iter->scaleZ)) == 4) { dumpframe(&*iter); iter++; fgets (line , 100 , pFile); } } else if (strcmp(str,"Rotation") == 0) { fgets (line , 100 , pFile); cout << line ; fgets (line , 100 , pFile); iter = frames.begin(); while (sscanf(line, "%u %f",&num,&iter->rotation) == 2) { dumpframe(&*iter); iter++; fgets (line , 100 , pFile); } } } fclose (pFile); vector<string> vec1 = ofSplitString(filename, "/"); vector<string> vec2 = ofSplitString(vec1.back(), "."); prefix = vec2.front(); }
static int32_t fsread(Usbfs *fs, Fid *fid, void *data, int32_t count, int64_t offset) { int cn, qt; char *s, *se; char buf[2048]; /* keep this large for ifstats */ Buf *bp; Conn *c; Ether *e; Qid q; q = fid->qid; q.path &= ~fs->qid; e = fs->aux; s = buf; se = buf+sizeof(buf); qt = qtype(q.path); cn = qnum(q.path); switch(qt){ case Qroot: count = usbdirread(fs, q, data, count, offset, rootdirgen, nil); break; case Qaddr: s = seprintaddr(s, se, e->addr); count = usbreadbuf(data, count, offset, buf, s - buf); break; case Qnifstats: /* BUG */ case Qifstats: s = seprintifstats(s, se, e); if(e->seprintstats != nil) s = e->seprintstats(s, se, e); count = usbreadbuf(data, count, offset, buf, s - buf); break; case Qnstats: /* BUG */ case Qstats: s = seprintstats(s, se, e); count = usbreadbuf(data, count, offset, buf, s - buf); break; case Qndir: count = usbdirread(fs, q, data, count, offset, conndirgen, nil); break; case Qndata: c = getconn(e, cn, 0); if(c == nil){ werrstr(Eio); return -1; } bp = recvp(c->rc); if(bp == nil) return -1; if(etherdebug > 1) dumpframe("etherin", bp->rp, bp->ndata); count = usbreadbuf(data, count, 0LL, bp->rp, bp->ndata); freebuf(e, bp); break; case Qnctl: s = seprint(s, se, "%11d ", cn); count = usbreadbuf(data, count, offset, buf, s - buf); break; case Qntype: c = getconn(e, cn, 0); if(c == nil) s = seprint(s, se, "%11d ", 0); else s = seprint(s, se, "%11d ", c->type); count = usbreadbuf(data, count, offset, buf, s - buf); break; default: sysfatal("usb: ether: fsread bug"); } return count; }