int aac_send_shutdown(struct aac_dev * dev) { struct fib * fibctx; struct aac_close *cmd; int status; fibctx = fib_alloc(dev); if (!fibctx) return -ENOMEM; fib_init(fibctx); cmd = (struct aac_close *) fib_data(fibctx); cmd->command = cpu_to_le32(VM_CloseAll); cmd->cid = cpu_to_le32(0xffffffff); status = fib_send(ContainerCommand, fibctx, sizeof(struct aac_close), FsaNormal, 1, 1, NULL, NULL); if (status == 0) fib_complete(fibctx); fib_free(fibctx); return status; }
/** * aac_get_containers - list containers * @common: adapter to probe * * Make a list of all containers on this controller */ int aac_get_containers(struct aac_dev *dev) { struct fsa_scsi_hba *fsa_dev_ptr; u32 index; int status = 0; struct aac_query_mount *dinfo; struct aac_mount *dresp; struct fib * fibptr; unsigned instance; fsa_dev_ptr = &(dev->fsa_dev); instance = dev->scsi_host_ptr->unique_id; if (!(fibptr = fib_alloc(dev))) return -ENOMEM; for (index = 0; index < MAXIMUM_NUM_CONTAINERS; index++) { fib_init(fibptr); dinfo = (struct aac_query_mount *) fib_data(fibptr); dinfo->command = cpu_to_le32(VM_NameServe); dinfo->count = cpu_to_le32(index); dinfo->type = cpu_to_le32(FT_FILESYS); status = fib_send(ContainerCommand, fibptr, sizeof (struct aac_query_mount), FsaNormal, 1, 1, NULL, NULL); if (status < 0 ) { printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n"); break; } dresp = (struct aac_mount *)fib_data(fibptr); if ((le32_to_cpu(dresp->status) == ST_OK) && (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) && (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) { fsa_dev_ptr->valid[index] = 1; fsa_dev_ptr->type[index] = le32_to_cpu(dresp->mnt[0].vol); fsa_dev_ptr->size[index] = le32_to_cpu(dresp->mnt[0].capacity); if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) fsa_dev_ptr->ro[index] = 1; } fib_complete(fibptr); /* * If there are no more containers, then stop asking. */ if ((index + 1) >= le32_to_cpu(dresp->count)){ break; } } fib_free(fibptr); fsa_dev[instance] = fsa_dev_ptr; return status; }
static int probe_container(struct aac_dev *dev, int cid) { struct fsa_scsi_hba *fsa_dev_ptr; int status; struct aac_query_mount *dinfo; struct aac_mount *dresp; struct fib * fibptr; unsigned instance; fsa_dev_ptr = &(dev->fsa_dev); instance = dev->scsi_host_ptr->unique_id; if (!(fibptr = fib_alloc(dev))) return -ENOMEM; fib_init(fibptr); dinfo = (struct aac_query_mount *)fib_data(fibptr); dinfo->command = cpu_to_le32(VM_NameServe); dinfo->count = cpu_to_le32(cid); dinfo->type = cpu_to_le32(FT_FILESYS); status = fib_send(ContainerCommand, fibptr, sizeof(struct aac_query_mount), FsaNormal, 1, 1, NULL, NULL); if (status < 0) { printk(KERN_WARNING "aacraid: probe_containers query failed.\n"); goto error; } dresp = (struct aac_mount *) fib_data(fibptr); if ((le32_to_cpu(dresp->status) == ST_OK) && (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) && (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) { fsa_dev_ptr->valid[cid] = 1; fsa_dev_ptr->type[cid] = le32_to_cpu(dresp->mnt[0].vol); fsa_dev_ptr->size[cid] = le32_to_cpu(dresp->mnt[0].capacity); if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) fsa_dev_ptr->ro[cid] = 1; } error: fib_complete(fibptr); fib_free(fibptr); return status; }
//This function will soon take an char ** of input vars int indexPage(struct argData *args) { //Lets get our IP address for fun uip_ipaddr_t ipaddr; uip_gethostaddr(ipaddr); char IPAdd[16]; sprintf(IPAdd, "%d.%d.%d.%d", (uint8_t)ipaddr[0], (uint8_t)(ipaddr[0] >> 8), (uint8_t)ipaddr[1], (uint8_t)(ipaddr[1] >> 8)); fib_send ( "<h1>Atmega 644 webserver</h1>" "<b>Stats:</b><br/>" "\tCHIP: Atmel Atmega 644 20Mhz 4Kb RAM.<br/>" #ifdef ENC28J60 "\tNIC: Microchip ENC28J60.<br/>" #elif CP2200 "\tNIC: Silicon Labs CP2200.<br/>" #endif "\tTCP/IP stack: uIP<br/>" "\tIP: " ); fib_send(IPAdd); fib_send ( "<br/><a href=\"?redlight=on\">turn on red light</a><br/>" "<a href=\"?redlight=off\">turn off red light</a><br/>" ); fib_send ( "<a href=\"?greenlight=on\">turn on green light</a><br/>" "<a href=\"?greenlight=off\">turn off green light</a><br/>" ); fib_send ( "<a href=\"?testlight=on\">turn on test light</a><br/>" "<a href=\"?testlight=off\">turn off test light</a><br/>" ); fib_send("\tARGS: <br/>"); int i; for(i = 0; i < 5; i ++) { if(args[i].argName) { if(strcmp(args[i].argName, "greenlight") == 0) { if(strcmp(args[i].argValue, "off") == 0) { PORTC |= 1; } else { PORTC &= ~1; } } if(strcmp(args[i].argName, "redlight") == 0) { if(strcmp(args[i].argValue, "off") == 0) { PORTC |= 2; } else { PORTC &= ~2; } } if(strcmp(args[i].argName, "testlight") == 0) { if(strcmp(args[i].argValue, "on") == 0) { PORTB |= 1; } else { PORTB &= ~1; } } fib_send("\t\t"); fib_send(args[i].argName); fib_send(": "); if(args[i].argValue) fib_send(args[i].argValue); fib_send("<br/>"); } } }
static int ioctl_send_fib(struct aac_dev * dev, void *arg) { struct hw_fib * kfib; struct fib *fibptr; fibptr = fib_alloc(dev); if(fibptr == NULL) return -ENOMEM; kfib = fibptr->fib; /* * First copy in the header so that we can check the size field. */ if (copy_from_user((void *)kfib, arg, sizeof(struct aac_fibhdr))) { fib_free(fibptr); return -EFAULT; } /* * Since we copy based on the fib header size, make sure that we * will not overrun the buffer when we copy the memory. Return * an error if we would. */ if(le32_to_cpu(kfib->header.Size) > sizeof(struct hw_fib) - sizeof(struct aac_fibhdr)) { fib_free(fibptr); return -EINVAL; } if (copy_from_user((void *) kfib, arg, le32_to_cpu(kfib->header.Size) + sizeof(struct aac_fibhdr))) { fib_free(fibptr); return -EFAULT; } if (kfib->header.Command == cpu_to_le32(TakeABreakPt)) { aac_adapter_interrupt(dev); /* * Since we didn't really send a fib, zero out the state to allow * cleanup code not to assert. */ kfib->header.XferState = 0; } else { if (fib_send(kfib->header.Command, fibptr, le32_to_cpu(kfib->header.Size) , FsaNormal, 1, 1, NULL, NULL) != 0) { fib_free(fibptr); return -EINVAL; } if (fib_complete(fibptr) != 0) { fib_free(fibptr); return -EINVAL; } } /* * Make sure that the size returned by the adapter (which includes * the header) is less than or equal to the size of a fib, so we * don't corrupt application data. Then copy that size to the user * buffer. (Don't try to add the header information again, since it * was already included by the adapter.) */ if (copy_to_user(arg, (void *)kfib, kfib->header.Size)) { fib_free(fibptr); return -EFAULT; } fib_free(fibptr); return 0; }
int error404(struct argData *args) { fib_send("<html><head><title>404 Not Found</title></head>"); fib_send("<body><h1>Error: 404</h1>"); fib_send("<b>Page not found!<br/></body></html>"); }
void webAppFunc() { //writeLn("webserver called\r\n"); enum { NEW_CONNECTION, OLD_CONNECTION } conState; while(1) { //writeLn("entering while loop\r\n"); if(uip_connected()) { //writeLn("new connection to webserver!\r\n"); conState = NEW_CONNECTION; } if(uip_newdata() && conState == NEW_CONNECTION) { //writeLn("new data detected\r\n"); uint16_t len = uip_datalen(); char *dataPtr = (char *)uip_appdata; //char *dataPtrBegin = dataPtr; if(strncmp(dataPtr, "GET ", 4) != 0) { conState = OLD_CONNECTION; uip_close(); fibre_yield(currentFibre); goto ENDLOOP; } while(*dataPtr ++ != ISO_space); char filename[20] = { 0 }; //There might be a better way to do this, I dunno char argumentData[100] = { 0 }; struct argData args[5] = { 0 }; pageFunc comm = NULL; if(dataPtr[1] == ISO_space) { strcpy(filename, "/index.html"); dataPtr ++; } else { char *tmpPtr = filename; while(*(tmpPtr ++) = *(dataPtr ++)) { if(*dataPtr == ISO_question || *dataPtr == ISO_space) { break; } } if(*dataPtr == ISO_question) { dataPtr ++; char *tmpPtr = argumentData; uint8_t counter = 0; while(counter < 5) { args[counter].argName = tmpPtr; while((*(tmpPtr ++) = *(dataPtr ++)) != ISO_equals); *(tmpPtr - 1) = 0x00; args[counter].argValue = tmpPtr; while(*dataPtr != ISO_amp && *dataPtr != ISO_space) *(tmpPtr ++) = *(dataPtr ++); *(tmpPtr ++) = 0x00; if(*dataPtr == ISO_space) break; dataPtr ++; counter ++; } } } comm = fls->findIndexString(fls, filename); if(comm) { fib_send("HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n"); comm(args); } else { fib_send("HTTP/1.0 404 Not Found\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n"); error404(args); } conState = OLD_CONNECTION; uip_close(); } ENDLOOP: //writeLn("About to Yield\r\n"); fibre_yield(currentFibre); //writeLn("return from yield\r\n"); } }