static int pdp_demux(void) { int ret; u8 ch; size_t len; struct pdp_info *dev = NULL; struct pdp_hdr hdr; /* read header */ ret = dpram_read(dpram_filp, &hdr, sizeof(hdr)); if (ret < 0) { return ret; } len = hdr.len - sizeof(struct pdp_hdr); /* check header */ down(&pdp_lock); dev = pdp_get_dev(hdr.id); if (dev == NULL) { printk("invalid id: %u, there is no existing device.\n", hdr.id); ret = -ENODEV; goto err; } /* read data */ switch (dev->type) { case DEV_TYPE_NET: ret = vnet_recv(dev, len); break; case DEV_TYPE_SERIAL: ret = vs_read(dev, len); break; default: ret = -1; } if (ret < 0) { goto err; } up(&pdp_lock); /* check stop byte */ ret = dpram_read(dpram_filp, &ch, sizeof(ch)); if (ret < 0 || ch != 0x7e) { return ret; } return 0; err: up(&pdp_lock); /* flush the remaining data including stop byte. */ dpram_flush_rx(dpram_filp, len + 1); return ret; }
static send_loop_back_packet(const char *data, int size) { struct pdp_info *dev = pdp_get_dev(LOOP_BACK_CHANNEL); if (loopback_ongoing) { pdp_mux(dev, data, size); loopback_res.nTransfered++; } }
static send_loop_back_packet(const char* data, int size) { struct pdp_info* dev = pdp_get_dev(LOOP_BACK_CHANNEL); if (loopback_ongoing) { //printk("send loopback packet start [%d]\n",loopback_res.nTransfered); pdp_mux(dev, data, size); //printk("send loopback packet end [%d]\n",loopback_res.nTransfered); loopback_res.nTransfered++; } }
static int pdp_deactivate(pdp_arg_t *pdp_arg, int force) { struct pdp_info *dev = NULL; DPRINTK(2, "BEGIN\n"); DPRINTK(1, "id: %d\n", pdp_arg->id); mutex_lock(&pdp_lock); if (pdp_arg->id == 1) { DPRINTK(1, "Channel ID is 1, we will remove the network device (pdp) of channel ID: %d.\n", pdp_arg->id + g_adjust); } else { DPRINTK(1, "Channel ID: %d\n", pdp_arg->id); } pdp_arg->id = pdp_arg->id + g_adjust; //pdp_arg->id += PDP_ID_ADJUST; DPRINTK(1, "ID is adjusted, new ID: %d\n", pdp_arg->id); dev = pdp_get_dev(pdp_arg->id); if (dev == NULL) { DPRINTK(1, "not found id: %d\n", pdp_arg->id); mutex_unlock(&pdp_lock); return -EINVAL; } if (!force && dev->flags & DEV_FLAG_STICKY) { DPRINTK(1, "sticky id: %u\n", pdp_arg->id); mutex_unlock(&pdp_lock); return -EACCES; } pdp_remove_dev(pdp_arg->id); mutex_unlock(&pdp_lock); if (dev->type == DEV_TYPE_NET) { DPRINTK(1, "%s(id: %u) network device removed\n", dev->vn_dev.net->name, dev->id); vnet_del_dev(dev->vn_dev.net); } else if (dev->type == DEV_TYPE_SERIAL) { struct tty_driver * tty_driver = get_tty_driver_by_id(dev); DPRINTK(1, "%s(id: %u) serial device removed\n", tty_driver->name, dev->id); vs_del_dev(dev); } kfree(dev); DPRINTK(2, "END\n"); return 0; }
static inline int pdp_add_dev(struct pdp_info *dev) { int slot; if (pdp_get_dev(dev->id)) return -EBUSY; for (slot = 0; slot < MAX_PDP_CONTEXT; slot++) { if (pdp_table[slot] == NULL) { pdp_table[slot] = dev; return slot; } } return -ENOSPC; }
static int pdp_deactivate(struct pdp_arg *pdp_arg, int force) { struct pdp_info *dev = NULL; down(&pdp_lock); pdp_arg->id = pdp_arg->id + g_adjust; DPRINTK(2, "ID is adjusted, new ID: %d\n", pdp_arg->id); dev = pdp_get_dev(pdp_arg->id); if (dev == NULL) { pr_err("[MULTIPDP] not found id: %u\n", pdp_arg->id); up(&pdp_lock); return -EINVAL; } if (!force && dev->flags & DEV_FLAG_STICKY) { pr_err("[MULTIPDP] sticky id: %u\n", pdp_arg->id); up(&pdp_lock); return -EACCES; } pdp_remove_dev(pdp_arg->id); up(&pdp_lock); if (dev->type == DEV_TYPE_NET) { #ifdef NO_TTY_MUTEX_VNET vnet_stop(dev->vn_dev.net); down(&pdp_txlock); pdp_net_activation_count--; #endif vnet_del_dev(dev->vn_dev.net); #ifdef NO_TTY_MUTEX_VNET up(&pdp_txlock); #endif } else if (dev->type == DEV_TYPE_SERIAL) { vs_del_dev(dev); } vfree(dev); return 0; }
static inline int pdp_add_dev(struct pdp_info *dev) { int slot; DPRINTK(2, "BEGIN\n"); if (pdp_get_dev(dev->id)) { EPRINTK("pdp_add_dev() Error ..%d already exist \n", dev->id); return -EBUSY; } for (slot = 0; slot < MAX_PDP_CONTEXT; slot++) { if (pdp_table[slot] == NULL) { pdp_table[slot] = dev; DPRINTK(2, "END\n"); return slot; } } EPRINTK("pdp_add_dev() Error ..%d There is no space to make %d \n", dev->id); return -ENOSPC; }
static int pdp_deactivate(pdp_arg_t *pdp_arg, int force) { struct pdp_info *dev = NULL; DPRINTK(1, "id: %d\n", pdp_arg->id); down(&pdp_lock); if (pdp_arg->id == 1) { DPRINTK(1, "Channel ID is 1, we will remove the network device (pdp) of channel ID: %d.\n", pdp_arg->id + g_adjust); } else { DPRINTK(1, "Channel ID: %d\n", pdp_arg->id); } pdp_arg->id = pdp_arg->id + g_adjust; //pdp_arg->id += PDP_ID_ADJUST; DPRINTK(1, "ID is adjusted, new ID: %d\n", pdp_arg->id); dev = pdp_get_dev(pdp_arg->id); if (dev == NULL) { DPRINTK(1, "not found id: %u\n", pdp_arg->id); up(&pdp_lock); return -EINVAL; } if (!force && dev->flags & DEV_FLAG_STICKY) { DPRINTK(1, "sticky id: %u\n", pdp_arg->id); up(&pdp_lock); return -EACCES; } pdp_remove_dev(pdp_arg->id); up(&pdp_lock); if (dev->type == DEV_TYPE_NET) { #ifdef NO_TTY_MUTEX_VNET //printk("<--- VNET Mutex lock : Before .. !!\n"); vnet_stop(dev->vn_dev.net); down(&pdp_txlock); pdp_net_activation_count--; //printk("<--- VNET Mutex lock : After .. !!\n"); #endif DPRINTK(1, "%s(id: %u) network device removed\n", dev->vn_dev.net->name, dev->id); vnet_del_dev(dev->vn_dev.net); #ifdef NO_TTY_MUTEX_VNET //printk("<--- VNET Mutex Unlock : Before .. !!\n"); up(&pdp_txlock); //printk("<--- VNET Mutex Unlock : After .. !!\n"); #endif } else if (dev->type == DEV_TYPE_SERIAL) { struct tty_driver * tty_driver = get_tty_driver_by_id(dev); DPRINTK(1, "%s(id: %u) serial device removed\n", tty_driver->name, dev->id); vs_del_dev(dev); } vfree(dev); return 0; }
//0x7F, pdp_hdr static int multipdp_demux(char *buf, int size) { int ret; u8 ch; size_t len; struct pdp_info *dev = NULL; struct pdp_hdr hdr; //printk("multipdp_demux : size = %d\n", size); //mutex_lock(&pdp_lock); memcpy( (void *)&hdr, (void *)buf, sizeof( struct pdp_hdr)); len = hdr.len - sizeof(struct pdp_hdr); dev = pdp_get_dev(hdr.id); if (dev == NULL) { printk("========================================= : (1)\n"); yhexdump((char*)&hdr, sizeof(struct pdp_hdr)); printk("========================================= : (2)\n"); yhexdump((char*)buf, size); printk("========================================= : (3)\n"); EPRINTK("invalid id: %u, there is no existing device.\n", hdr.id); multipdp_dump(); ret = -ENODEV; goto err; } if( buf[-1] != 0x7F) { printk("============ multipdp_demux : ******** not 0x7F \n"); } if( len > size ) { printk("============== multipdp_demux : len>size : len=%d, size=%d\n", size, len); } /* read data */ switch (dev->type) { case DEV_TYPE_NET: if( len > 1500 ) { printk("-------------> len is [%d]\n", len); multipdp_dump(); } //printk("multipdp_demux:vnet_recv(VNET) (1): len = %d\n", len); ret = multipdp_vnet_recv(dev, (char *)&buf[sizeof(struct pdp_hdr)], len); break; case DEV_TYPE_SERIAL: //printk("multipdp_demux:vs_read(SERIAL) : len = %d\n", len); ret = multipdp_vs_read(dev, (char *)&buf[sizeof(struct pdp_hdr)], len); break; default: printk("-------------> type invalid [%d]\n", dev->type); multipdp_dump(); ret = -1; } if (ret < 0) { goto err; } /* check stop byte */ ch = buf[hdr.len]; if ( ch != 0x7e) { printk(" *******Not 0x7E ... !!!!\n"); //mutex_unlock(&pdp_lock); return ret; } //mutex_unlock(&pdp_lock); return ret; err: /* flush the remaining data including stop byte. */ //mutex_unlock(&pdp_lock); return ret; }
static int multipdp_demux(char *buf, int size) { int ret; u8 ch; size_t len; struct pdp_info *dev = NULL; struct pdp_hdr hdr; /* mutex_lock(&pdp_lock); */ memcpy((void *)&hdr, (void *)buf, sizeof(struct pdp_hdr)); len = hdr.len - sizeof(struct pdp_hdr); dev = pdp_get_dev(hdr.id); if (dev == NULL) { pr_err("[MULTIPDP] invalid id: %u, no existing device.\n", hdr.id); yhexdump((char *)&hdr, sizeof(struct pdp_hdr)); multipdp_dump(); ret = -ENODEV; goto err; } if (buf[-1] != 0x7F) pr_err("[MULTIPDP] Start byte is not 0x7F\n"); if (len > size) pr_err("[MULTIPDP] len>size : len=%d, size=%d\n", size, len); /* read data */ switch (dev->type) { case DEV_TYPE_NET: if (len > 1500) { pr_err("[MULTIPDP] TYPE_NET len is [%d]\n", len); multipdp_dump(); } ret = multipdp_vnet_recv(dev, (char *)&buf[sizeof(struct pdp_hdr)], len); break; case DEV_TYPE_SERIAL: ret = multipdp_vs_read(dev, (char *)&buf[sizeof(struct pdp_hdr)], len); break; default: pr_err("[MULTIPDP] Type invalid [%d]\n", dev->type); multipdp_dump(); ret = -1; } if (ret < 0) goto err; /* check stop byte */ ch = buf[hdr.len]; if (ch != 0x7e) { pr_err("[MULTIPDP] End byte is Not 0x7E ... !!!!\n"); /* mutex_unlock(&pdp_lock); */ return ret; } /* mutex_unlock(&pdp_lock); */ return ret; err: /* flush the remaining data including stop byte. */ /* mutex_unlock(&pdp_lock); */ return ret; }