#if 1
//Temporarly for debug
static void print_packet(uchar_t *pkt, int size) {
- PrintDebug("Vnet: print_data_packet: size: %d\n", size);
+ PrintDebug("Virtio Nic: print_data_packet: size: %d\n", size);
v3_hexdump(pkt, size, NULL, 0);
}
struct virtio_net_state *virtio_state = (struct virtio_net_state *)private_data;
if (virtio_state == temp_net_states[0])
- __virtio_dev_send(buf, count, temp_net_states[1]);
+ __virtio_dev_send(buf, count, temp_net_states[1]);
+
+ if (virtio_state == temp_net_states[1]){ //return a RARP packet
+ __virtio_dev_send(buf, count, temp_net_states[0]);
+ }
return count;
}
uint8_t * buf = NULL;
uint32_t len = buf_desc->length;
- PrintDebug("Handling Virtio Net write, net_state: %p\n", virtio);
+ PrintDebug("Virtio NIC: Handling Virtio Write, net_state: %p\n", virtio);
if (guest_pa_to_host_va(virtio->virtio_dev->vm, buf_desc->addr_gpa, (addr_t *)&(buf)) == -1) {
PrintError("Could not translate buffer address\n");
PrintDebug("VIRTIO NIC: sending packet to net_state %p, size:%d", virtio, size);
if (!raw) {
- data_len -= hdr_len;
+ data_len -= hdr_len;
}
build_receive_header(&hdr, buf, 1);
//copy header to the header descriptor
memcpy((void *)hdr_addr, &hdr, sizeof(struct virtio_net_hdr));
+ //Zheng 01/02/2010: zero payload
+ if (offset >= data_len) {
+ hdr_desc->flags &= ~VIRTIO_NEXT_FLAG;
+ }
+
//copy data to the next descriptors
- for (buf_idx = 0; offset < data_len; buf_idx = q->desc[hdr_idx].next) {
+ //Zheng 01/02/2010: put data into the next descriptor, rather than 0!
+ for (buf_idx = hdr_desc->next; offset < data_len; buf_idx = q->desc[hdr_idx].next) {
+ // for (buf_idx = 0; offset < data_len; buf_idx = q->desc[hdr_idx].next) {
struct vring_desc * buf_desc = &(q->desc[buf_idx]);
uint32_t len = 0;
- buf_desc->flags = VIRTIO_NEXT_FLAG;
+ //Zheng 01/02/2010: commented this - we need to check
+ // if there still is some data left
+ //buf_desc->flags = VIRTIO_NEXT_FLAG;
+
+ PrintError("JACK: copying packet to up desc (len = %d)\n", data_len - offset);
+ v3_hexdump(buf + offset, data_len - offset, NULL, 0);
+
len = copy_data_to_desc(virtio, buf_desc, buf + offset, data_len - offset);
offset += len;
+
+ //Zheng 01/02/2010: check if there still is some data left
+ if (offset < data_len) {
+ buf_desc->flags = VIRTIO_NEXT_FLAG;
+ }
+
buf_desc->length = len; // TODO: do we need this?
+ PrintError("JACK: setting buffer descriptor length to %d)\n", buf_desc->length);
}
+
q->used->ring[q->used->index % q->queue_size].id = q->avail->ring[q->cur_avail_idx % q->queue_size];
- q->used->ring[q->used->index % q->queue_size].length = data_len; // What do we set this to????
+ q->used->ring[q->used->index % q->queue_size].length = data_len + hdr_len; // This should be the total length of data sent to guest (header+pkt_data)
q->used->index++;
q->cur_avail_idx++;
virtio->virtio_cfg.pci_isr = 0x1;
}
+
+ PrintError("\n\n\n\n");
return offset;
}