int pcmcia_get_next_tuple(client_handle_t handle, tuple_t *tuple) { struct pcmcia_socket *s; if (CHECK_HANDLE(handle)) return CS_BAD_HANDLE; s = SOCKET(handle); return pccard_get_next_tuple(s, handle->Function, tuple); }
/** * pccard_loop_tuple() - loop over tuples in the CIS * @s: the struct pcmcia_socket where the card is inserted * @function: the device function we loop for * @code: which CIS code shall we look for? * @parse: buffer where the tuple shall be parsed (or NULL, if no parse) * @priv_data: private data to be passed to the loop_tuple function. * @loop_tuple: function to call for each CIS entry of type @function. IT * gets passed the raw tuple, the paresed tuple (if @parse is * set) and @priv_data. * * pccard_loop_tuple() loops over all CIS entries of type @function, and * calls the @loop_tuple function for each entry. If the call to @loop_tuple * returns 0, the loop exits. Returns 0 on success or errorcode otherwise. */ int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t code, cisparse_t *parse, void *priv_data, int (*loop_tuple) (tuple_t *tuple, cisparse_t *parse, void *priv_data)) { tuple_t tuple; cisdata_t *buf; int ret; buf = kzalloc(256, GFP_KERNEL); if (buf == NULL) { #ifdef CONFIG_DEBUG_PRINTK dev_printk(KERN_WARNING, &s->dev, "no memory to read tuple\n"); #else dev_; #endif return -ENOMEM; } tuple.TupleData = buf; tuple.TupleDataMax = 255; tuple.TupleOffset = 0; tuple.DesiredTuple = code; tuple.Attributes = 0; ret = pccard_get_first_tuple(s, function, &tuple); while (!ret) { if (pccard_get_tuple_data(s, &tuple)) goto next_entry; if (parse) if (pcmcia_parse_tuple(&tuple, parse)) goto next_entry; ret = loop_tuple(&tuple, parse, priv_data); if (!ret) break; next_entry: ret = pccard_get_next_tuple(s, function, &tuple); } kfree(buf); return ret; }
static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, loff_t off, size_t count) { tuple_t tuple; int status, i; loff_t pointer = 0; ssize_t ret = 0; u_char *tuplebuffer; u_char *tempbuffer; tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL); if (!tuplebuffer) return -ENOMEM; tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL); if (!tempbuffer) { ret = -ENOMEM; goto free_tuple; } memset(&tuple, 0, sizeof(tuple_t)); tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON; tuple.DesiredTuple = RETURN_FIRST_TUPLE; tuple.TupleOffset = 0; status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple); while (!status) { tuple.TupleData = tuplebuffer; tuple.TupleDataMax = 255; memset(tuplebuffer, 0, sizeof(u_char) * 255); status = pccard_get_tuple_data(s, &tuple); if (status) break; if (off < (pointer + 2 + tuple.TupleDataLen)) { tempbuffer[0] = tuple.TupleCode & 0xff; tempbuffer[1] = tuple.TupleLink & 0xff; for (i = 0; i < tuple.TupleDataLen; i++) tempbuffer[i + 2] = tuplebuffer[i] & 0xff; for (i = 0; i < (2 + tuple.TupleDataLen); i++) { if (((i + pointer) >= off) && (i + pointer) < (off + count)) { buf[ret] = tempbuffer[i]; ret++; } } } pointer += 2 + tuple.TupleDataLen; if (pointer >= (off + count)) break; if (tuple.TupleCode == CISTPL_END) break; status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple); } kfree(tempbuffer); free_tuple: kfree(tuplebuffer); return (ret); }