fix cec padding issues for 64-bit kernels. Reference: /n/patches.lsub.org/patch/cec64 Date: Tue Oct 9 16:32:44 CES 2012 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/cec/cec.c Thu Apr 26 11:22:50 2012 +++ /sys/src/cmd/cec/cec.c Tue Sep 25 20:49:11 2012 @@ -6,7 +6,6 @@ #include #include #include /* really! */ -#include #include #include #include "cec.h" @@ -261,7 +260,7 @@ ntab = 0; memset(q.dst, 0xff, Eaddrlen); memset(q.src, 0, Eaddrlen); - q.etype = htons(Etype); + putbe(q.etype, Etype, 2); q.type = Tdiscover; q.len = 0; q.conn = 0; @@ -349,7 +348,7 @@ case -1: exits0(0); } - if(isdigit(buf[0])){ + if(buf[0] >= '0' && buf[0] <= '9'){ buf[n] = 0; i = atoi(buf); if(i >= 0 && i < ntab) @@ -360,14 +359,14 @@ } void -sethdr(Pkt *pp, int type) +sethdr(Pkt *p, int type) { - memmove(pp->dst, con->ea, Eaddrlen); - memset(pp->src, 0, Eaddrlen); - pp->etype = htons(Etype); - pp->type = type; - pp->len = 0; - pp->conn = contag; + memmove(p->dst, con->ea, Eaddrlen); + memset(p->src, 0, Eaddrlen); + putbe(p->etype, Etype, 2); + p->type = type; + p->len = 0; + p->conn = contag; } void @@ -401,7 +400,7 @@ w = Iowait; } timewait(w); - netget(&rpk, 1000); + netget(&rpk, sizeof rpk); alarm(0); } if(rpk.type != Tinitb) @@ -527,9 +526,8 @@ } break; case Fcec: - if(memcmp(spk.src, ea, 6) != 0 || ntohs(spk.etype) != Etype) + if(memcmp(spk.src, ea, 6) != 0 || getbe(spk.etype, 2) != Etype) continue; -// if(spk.type == Toffer && memcmp(spk.dst, bcast, 6) != 0){ if(spk.type == Toffer && spk.seq == 0){ muxfree(m); return 1; --- /sys/src/cmd/cec/cec.h Thu Apr 26 11:22:50 2012 +++ /sys/src/cmd/cec/cec.h Wed Jul 11 22:06:13 2012 @@ -5,12 +5,12 @@ typedef struct { uchar dst[Eaddrlen]; uchar src[Eaddrlen]; - ushort etype; + uchar etype[2]; uchar type; uchar conn; uchar seq; uchar len; - uchar data[1500]; + uchar data[256]; } Pkt; enum { --- /sys/src/cmd/cec/mux.c Thu Apr 26 11:22:50 2012 +++ /sys/src/cmd/cec/mux.c Tue Oct 9 05:32:53 2012 @@ -4,10 +4,11 @@ typedef struct { char type; - char pad[3]; Pkt p; } Muxmsg; +#define Muxo (offsetof(Muxmsg, p)) + typedef struct { int fd; int type; @@ -38,7 +39,7 @@ m.type = Fcec; while((l = netget(&m.p, sizeof m.p)) > 0) - if(write(cfd, &m, l+4) != l+4) + if(write(cfd, &m, l+Muxo) != l+Muxo) break; exits(""); } @@ -47,10 +48,12 @@ muxkbd(int kfd, int cfd) { Muxmsg m; + int o; m.type = Fkbd; + o = offsetof(Muxmsg, p.data[0]); while((m.p.len = read(kfd, m.p.data, sizeof m.p.data)) > 0) - if(write(cfd, &m, m.p.len+22) != m.p.len+22) + if(write(cfd, &m, o+m.p.len) != o+m.p.len) break; m.type = Ffatal; write(cfd, &m, 4); @@ -152,7 +155,7 @@ m->step <<= 1; return Ftimeout; } - memcpy(p, &m->m.p, sizeof *p); + memcpy(p, &m->m.p, r-Muxo); return m->m.type; } --- /sys/src/cmd/cec/utils.c Thu Apr 26 11:22:50 2012 +++ /sys/src/cmd/cec/utils.c Tue Oct 9 05:29:55 2012 @@ -41,12 +41,12 @@ fprint(2, "%s\n", line); sprint(line + r*Perch, "%.2x ", buf[i]); } + if(n % 16 > 0) + fprint(2, "%s\n", line); } void dump(uchar *p, int n) { format(p, n, 0); - if(n % 16 > 0) - print("%s\n", line); }