++static void board_led_link_up(state_entry_t * pState)
++{
++ led_arr[pState->led].state = LED_ON;
++ if (led_arr[pState->led].timer_running == 0)
++ led_on(pState);
++ return;
++}
++
++static void board_led_link_down(state_entry_t * pState)
++{
++ led_arr[pState->led].state = LED_OFF;
++ if (led_arr[pState->led].timer_running == 0)
++ led_off(pState);
++ return;
++}
++
++static void add_led_timer(state_entry_t * pState)
++{
++ led_arr[pState->led].pTimer->expires =
++ jiffies + HZ * (pState->param) / 1000;
++ led_arr[pState->led].param = pState->param;
++ led_arr[pState->led].pTimer->data = pState;
++ add_timer(led_arr[pState->led].pTimer);
++}
++
++static void board_led_activity_on(state_entry_t * pState)
++{
++ if (led_arr[pState->led].timer_running == 0) {
++ led_on(pState);
++ add_led_timer(pState);
++ led_arr[pState->led].timer_running = 1;
++ led_arr[pState->led].state = LED_BLINK_UP;
++ } else if (led_arr[pState->led].timer_running > 0xF0) {
++ led_arr[pState->led].state = LED_BLINK_UP;
++ led_arr[pState->led].pTimer->expires =
++ jiffies + HZ * (pState->param) / 1000;
++ led_arr[pState->led].param = pState->param;
++ led_arr[pState->led].pTimer->data = pState;
++ }
++ return;
++}
++
++static void board_led_activity_off(state_entry_t * pState)
++{
++ if (led_arr[pState->led].timer_running == 0) {
++ led_off(pState);
++ add_led_timer(pState);
++ led_arr[pState->led].timer_running = 1;
++ led_arr[pState->led].state = LED_BLINK_UP;
++ } else if (led_arr[pState->led].timer_running > 0xF0) {
++ led_arr[pState->led].state = LED_BLINK_UP;
++ led_arr[pState->led].pTimer->expires =
++ jiffies + HZ * (pState->param) / 1000;
++ led_arr[pState->led].param = pState->param;
++ led_arr[pState->led].pTimer->data = pState;
++ }
++ return;
++}
++
++static void board_led_link_flash(state_entry_t * pState)
++{
++ if (led_on(pState))
++ return;
++ if (led_arr[pState->led].timer_running == 0)
++ add_led_timer(pState);
++ else
++ led_arr[pState->led].param = pState->param;
++ led_arr[pState->led].timer_running = 0xFF;
++ led_arr[pState->led].state = LED_FLASH;
++ return;
++}
++
++static void led_timer_func(unsigned long data)
++{
++ state_entry_t *pState = NULL;
++ mod_entry_t *pMod = NULL;
++ unsigned int flags;
++
++ spin_lock_irqsave(&config_lock, flags);
++
++ pState = (state_entry_t *) data;
++
++ if (led_arr[pState->led].state == LED_BLINK_DOWN) {
++ led_arr[pState->led].timer_running = 0;
++ if (pState->mode == 2)
++ led_arr[pState->led].state = LED_OFF;
++ else
++ led_arr[pState->led].state = LED_ON;
++ } else if (led_arr[pState->led].state == LED_BLINK_UP) {
++ led_arr[pState->led].pTimer->expires =
++ jiffies + HZ * (led_arr[pState->led].param) / 1000;
++ led_arr[pState->led].pTimer->data = pState;
++ add_timer(led_arr[pState->led].pTimer);
++ if (pState->mode == 2) {
++ led_off(pState);
++ led_arr[pState->led].state = LED_BLINK_DOWN;
++ } else {
++ led_on(pState);
++ led_arr[pState->led].state = LED_BLINK_DOWN;
++ }
++ led_arr[pState->led].timer_running = 1;
++ } else if (led_arr[pState->led].state == LED_FLASH) {
++ led_arr[pState->led].pTimer->expires =
++ jiffies + HZ * (led_arr[pState->led].param) / 1000;
++ led_arr[pState->led].pTimer->data = pState;
++ add_timer(led_arr[pState->led].pTimer);
++
++ if (led_arr[pState->led].timer_running == 0xFF) {
++ led_off(pState);
++ led_arr[pState->led].timer_running--;
++ } else {
++ led_on(pState);
++ led_arr[pState->led].timer_running++;
++ }
++ spin_unlock_irqrestore(&config_lock, flags);
++ return;
++ } else if (led_arr[pState->led].state == LED_OFF) {
++ led_off(pState);
++ led_arr[pState->led].timer_running = 0;
++ } else if (led_arr[pState->led].state == LED_ON) {
++ led_on(pState);
++ led_arr[pState->led].timer_running = 0;
++ }
++ spin_unlock_irqrestore(&config_lock, flags);
++ return;
++}
++
++static ssize_t proc_read_led_fops(struct file *filp,
++ char *buf, size_t count, loff_t * offp)
++{
++ char *pdata = NULL;
++ int i = 0, j = 0, len = 0, totallen = 0;
++ char line[255];
++
++ if (*offp != 0)
++ return 0;
++
++ pdata = buf;
++ len += sprintf(line, "LEDS Registered for use are:");
++ for (i = 0; i < MAX_LED_ID; i++)
++ if (led_arr[i].led != NULL)
++ len += sprintf(&line[len], " %d ", i);
++ line[len++] = '\n';
++
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++ len = 0;
++ len = sprintf(line, "USER MODULE INFORMATION:\n");
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++ len = 0;
++ for (i = 0; i < MAX_MOD_ID; i++) {
++ if (modArr[i] != NULL) {
++ len = sprintf(line, " Module ID = %d \n", i);
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++ len = 0;
++ for (j = 0; j < MAX_STATE_ID; j++) {
++ if (modArr[i]->states[j] != NULL) {
++ len = sprintf(line, " State = %d , Led = %d,", j,
++ modArr[i]->states[j]->led);
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++
++ len = 0;
++ switch (modArr[i]->states[j]->mode) {
++ case 1:
++ len = sprintf(line, " Mode = OFF\n");
++ break;
++ case 2:
++ len = sprintf(line, " Mode = BLINK_ON , On Time(ms) = %d\n",
++ (unsigned int) modArr[i]->states[j]->
++ param);
++ break;
++ case 3:
++ len = sprintf(line, " Mode = BLINK_OFF , Off Time(ms) = %d\n",
++ (unsigned int) modArr[i]->states[j]->
++ param);
++ break;
++ case 4:
++ len = sprintf(line, " Mode = ON \n");
++ break;
++ case 5:
++ len = sprintf(line, " Mode = FLASH , Time Period(ms) = %d\n",
++ (unsigned int) modArr[i]->states[j]->
++ param);
++ break;
++ default:
++ break;
++
++ }
++ copy_to_user(pdata, line, len);
++ pdata += len;
++ totallen += len;
++
++ len = 0;
++ }
++ }
++ }
++ }
++ /* Return with configuration information for LEDs */
++ *offp = totallen;
++ return totallen;
++}
++
++static ssize_t proc_write_led_fops(struct file *filp, const char *buffer, size_t count, loff_t * offp)
++{
++ char *pdata = NULL, *ptemp = NULL;
++ char line[10], temp[10];
++ int i = 0;
++ int mod = 0xFFFF, state = 0xFFFF;
++ int flag = 0;
++
++ /* Check if this write is for configuring stuff */
++ if (*(int *) (buffer) == 0xFFEEDDCC) {
++ printk("<1>proc write:Calling Configuration\n");
++ config_led((unsigned long) (buffer + sizeof(int)));
++ return count;
++ }
++
++ if (count >= 10) {
++ printk("<1>proc write:Input too long,max length = %d\n", 10);
++ return count;
++ }
++ memset(temp, 0x00, 10);
++ memset(line, 0x00, 10);
++ copy_from_user(line, buffer, count);
++ line[count] = 0x00;
++ pdata = line;
++ ptemp = temp;
++ while (flag == 0) {
++ if (i > 10)
++ break;
++ if (((*pdata) >= '0') && ((*pdata) <= '9')) {
++ *ptemp = *pdata;
++ ptemp++;
++ } else if ((*pdata) == ',') {
++ *ptemp = 0x00;
++ flag = 1;
++ }
++ pdata++;
++ i++;
++ };
++ if (flag == 1)
++ mod = led_atoi(temp);
++ else
++ return count;
++
++ ptemp = temp;
++ *ptemp = 0x00;
++ flag = 0;
++ while (flag == 0) {
++ if (i > 10)
++ break;
++ if (((*pdata) >= '0') && ((*pdata) <= '9')) {
++ *ptemp = *pdata;
++ ptemp++;
++ } else if ((*pdata) == 0x00) {
++ *ptemp = 0x00;
++ flag = 1;
++ }
++ pdata++;
++ i++;
++ };
++ if (flag == 1)
++ state = led_atoi(temp);
++ else
++ return count;
++ if ((mod == 0xFFFF) || (state == 0xFFFF))
++ return count;
++ else
++ led_operation(mod, state);
++ return count;
++}
++
++static int config_led(unsigned long y)
++{
++ config_elem_t *pcfg = NULL;
++ char *pdata = NULL;
++ int i;
++ int length = 0, number = 0;
++ unsigned int flags;
++
++ spin_lock_irqsave(&config_lock, flags);
++
++ /* ioctl to configure */
++ length = *((int *) y);
++ pdata = (char *) y + sizeof(int);
++ number = (length - sizeof(int)) / sizeof(config_elem_t);
++ pcfg = (config_elem_t *) (pdata);
++
++ /* Check if an earlier configuration exists IF yes free it up */
++ free_memory();
++
++ for (i = 0; i < number; i++) {
++ /* If no structure has been allocated for the module do so */
++ if (modArr[pcfg->name] == NULL) {
++ printk("<1>module = %d\n", pcfg->name);
++ if (pcfg->name >= MAX_MOD_ID) {
++ printk
++ ("<1>Exiting Configuration: Module ID too large %d\n",
++ pcfg->name);
++ free_memory();
++ spin_unlock_irqrestore(&config_lock, flags);
++ return -1;
++ }
++ modArr[pcfg->name] = kmalloc(sizeof(mod_entry_t), GFP_KERNEL);
++ if (modArr[pcfg->name] == NULL) {
++ printk
++ ("<1>Exiting Configuration: Error in allocating memory\n");
++ free_memory();
++ spin_unlock_irqrestore(&config_lock, flags);
++ return -1;
++ }
++ memset(modArr[pcfg->name], 0x00, sizeof(mod_entry_t));
++ }
++
++ /* if no structure is allocated previously for this state
++ allocate a structure, if it's already there fill it up */
++ if (modArr[pcfg->name]->states[pcfg->state] == NULL) {
++ printk("<1>STATE = %d\n", pcfg->state);
++ if (pcfg->state >= MAX_STATE_ID) {
++ printk("<1>Exiting Configuration: State ID too large\n");
++ free_memory();
++ spin_unlock_irqrestore(&config_lock, flags);
++ return -1;
++ }
++ modArr[pcfg->name]->states[pcfg->state] =
++ kmalloc(sizeof(state_entry_t), GFP_KERNEL);
++ if (modArr[pcfg->name]->states[pcfg->state] == NULL) {
++ free_memory();
++ spin_unlock_irqrestore(&config_lock, flags);
++ return -1;
++ }
++ memset(modArr[pcfg->name]->states[pcfg->state], 0x00,
++ sizeof(state_entry_t));
++ }
++ /* Fill up the fields of the state */
++ if (pcfg->led >= MAX_LED_ID) {
++ printk("<1>led = %d\n", pcfg->led);
++ free_memory();
++ spin_unlock_irqrestore(&config_lock, flags);
++ return -1;
++ }
++ modArr[pcfg->name]->states[pcfg->state]->led = pcfg->led;
++ modArr[pcfg->name]->states[pcfg->state]->mode = pcfg->mode;
++ modArr[pcfg->name]->states[pcfg->state]->param = pcfg->param;
++ switch (pcfg->mode) {
++ case 1:
++ modArr[pcfg->name]->states[pcfg->state]->handler =
++ board_led_link_down;
++ break;
++ case 2:
++ case 3:
++ case 5:
++ if (pcfg->mode == 2)
++ modArr[pcfg->name]->states[pcfg->state]->handler =
++ board_led_activity_on;
++ else if (pcfg->mode == 3)
++ modArr[pcfg->name]->states[pcfg->state]->handler =
++ board_led_activity_off;
++ else
++ modArr[pcfg->name]->states[pcfg->state]->handler =
++ board_led_link_flash;
++ break;
++ case 4:
++ modArr[pcfg->name]->states[pcfg->state]->handler =
++ board_led_link_up;
++ break;
++ default:
++ printk("<1>Exiting Configuration: Unknown LED Mode\n");
++ free_memory();
++ spin_unlock_irqrestore(&config_lock, flags);
++ return -1;
++ }
++ pcfg++;
++ }
++ spin_unlock_irqrestore(&config_lock, flags);
++ return 0;