Example #1
0
File: spam.c Project: astro/lun1k
void ram() {
    lcdClear();

    lcdPrintln("SPAM:");
    while(getInputRaw() != BTN_LEFT) {
        char c[2] = {0, 0};
        c[0] = (char)getRandom();

        uint8_t pkt[32];
        MO_TYPE_set(pkt, c[0]);
        MO_GEN_set(pkt, 0xFF);
        if (c[0] >= 'A' && c[0] <= 'Z')
            MO_TIME_set(pkt, 1313803870);
        else if (c[0] >= 'a' && c[0] <= 'z')
            MO_TIME_set(pkt, getRandom() % 16777216);
        else
            MO_TIME_set(pkt, (uint32_t)getRandom());
        strcpy((char *)MO_BODY(pkt), "chaosbay.camp.ccc.de");

        if (!mesh_sanity(pkt)) {
            lcdPrint("Sending: ");
            lcdPrintln(c);
            lcdRefresh();

            MPKT *mpkt = meshGetMessage(c[0]);
            mpkt->flags = MF_USED;
            memcpy(mpkt->pkt, pkt, 32);
        }
    }
}
Example #2
0
void mesh_sendloop(void){
    int ctr=0;
    __attribute__ ((aligned (4))) uint8_t buf[32];
    int status;
    uint32_t rnd=0xffffffff;

    if(meshnice)
        rnd=getRandom();

    nrf_config_get(&oldconfig);
    nrf_set_channel(MESH_CHANNEL);
    nrf_set_tx_mac(strlen(MESH_MAC),(uint8_t*)MESH_MAC);

    // Update [T]ime packet
    MO_TIME_set(meshbuffer[0].pkt,getSeconds());
    MO_GEN_set(meshbuffer[0].pkt,meshgen);
    if(GLOBAL(privacy)==0)
        uint32touint8p(GetUUID32(),MO_BODY(meshbuffer[0].pkt));
    else
        uint32touint8p(0,MO_BODY(meshbuffer[0].pkt));

    MO_BODY(meshbuffer[0].pkt)[4]=meshnice;

    for (int i=0;i<MESHBUFSIZE;i++){
        if(!meshbuffer[i].flags&MF_USED)
            continue;
        if(meshbuffer[i].flags&MF_LOCK)
            continue;
        if(meshnice&0xf){
            if((rnd++)%0xf < (meshnice&0x0f)){
                meshincctr++;
                continue;
            };
        };
        ctr++;
        memcpy(buf,meshbuffer[i].pkt,MESHPKTSIZE);
        status=nrf_snd_pkt_crc_encr(MESHPKTSIZE,buf,meshkey);
        //Check status? But what would we do...
    };

    nrf_config_set(&oldconfig);
};
Example #3
0
MPKT * meshGetMessage(uint8_t type){
    int free=-1;
    for(int i=0;i<MESHBUFSIZE;i++){
        if ( ((meshbuffer[i].flags&MF_USED)==0) && free<0 )
            free=i;
        if ( (meshbuffer[i].flags&MF_USED) &&
                (MO_TYPE(meshbuffer[i].pkt) == type)){
            free=i;
            break;
        };
    };
    if(free==-1){ // Buffer full. Ah well. Kill a random packet
        free=1; // XXX: GetRandom()?
        meshbuffer[free].flags=MF_FREE;
    };
    if(meshbuffer[free].flags==MF_FREE){
        memset(&meshbuffer[free],0,sizeof(MPKT));
        MO_TYPE_set(meshbuffer[free].pkt,type);
        MO_GEN_set(meshbuffer[free].pkt,meshgen);
        meshbuffer[free].flags=MF_USED;
    };
    return &meshbuffer[free];
};