Skip to content

Commit

Permalink
Use line disc 29, add option to make the driver less chatty
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodolfo Zitellini committed Sep 27, 2023
1 parent e2f0f16 commit a459fa0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 48 deletions.
2 changes: 1 addition & 1 deletion setup_and_run
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ sudo insmod src/tashtalk.ko
#sudo ./discipline

sudo stty -F /dev/ttyUSB0 crtscts
sudo ldattach -d -s 1000000 PPP /dev/ttyUSB0
sudo ldattach -d -s 1000000 29 /dev/ttyUSB0

#echo 'file hello.c line 327 +p' > /sys/kernel/debug/dynamic_debug/control
102 changes: 55 additions & 47 deletions src/tashtalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ static int tash_maxdev = TASH_MAX_CHAN;
module_param(tash_maxdev, int, 0);
MODULE_PARM_DESC(tash_maxdev, "Maximum number of tashtalk devices");

#ifndef TASH_DEBUG
#define TASH_DEBUG 0
#endif
static unsigned int tash_debug = TASH_DEBUG;

static void tashtalk_send_ctrl_packet(struct tashtalk *tt, unsigned char dst, unsigned char src, unsigned char type);

static void tash_setbits(struct tashtalk *tt, unsigned char addr) {
Expand All @@ -63,7 +68,8 @@ static void tash_setbits(struct tashtalk *tt, unsigned char addr) {
byte = addr / 8 + 1; // skip initial command byte
pos = (addr % 8);

printk(KERN_DEBUG "TashTalk: setting address %i (byte %i bit %i) for you.", addr, byte - 1, pos);
if (tash_debug)
printk(KERN_DEBUG "TashTalk: setting address %i (byte %i bit %i) for you.", addr, byte - 1, pos);

bits[0] = 0x02; // the command
bits[byte] = (1<<pos);
Expand Down Expand Up @@ -166,8 +172,10 @@ static void tt_send_frame(struct tashtalk *tt, unsigned char *icp, int len)
tt->xhead = tt->xbuff + actual;

print_hex_dump_bytes("TashTalk: LLAP OUT frame sans CRC: ", DUMP_PREFIX_NONE, icp, len);

if (tash_debug)
printk(KERN_DEBUG "TashTalk: transmit actual %i, requested %i", actual, len);

printk(KERN_DEBUG "TashTalk: transmit actual %i, requested %i", actual, len);
if (actual == len) {
clear_bit(TTY_DO_WRITE_WAKEUP, &tt->tty->flags);
netif_wake_queue(tt->dev);
Expand Down Expand Up @@ -198,17 +206,17 @@ static void tash_transmit_worker(struct work_struct *work)
clear_bit(TTY_DO_WRITE_WAKEUP, &tt->tty->flags);
spin_unlock_bh(&tt->lock);
netif_wake_queue(tt->dev);
printk(KERN_DEBUG "TashTalk: transmission finished, on to next");
if (tash_debug) printk(KERN_DEBUG "TashTalk: transmission finished, on to next");
return;
}

// Send whatever is there to send
// This function will be calleg again if xleft <= 0
printk(KERN_DEBUG "TashTalk: trasmit remaining bytes %i", tt->xleft);
if (tash_debug) printk(KERN_DEBUG "TashTalk: trasmit remaining bytes %i", tt->xleft);
actual = tt->tty->ops->write(tt->tty, tt->xhead, tt->xleft);
tt->xleft -= actual;
tt->xhead += actual;
printk(KERN_DEBUG "TashTalk: Trasmitted actual bytes %i", actual);
if (tash_debug) printk(KERN_DEBUG "TashTalk: Trasmitted actual bytes %i", actual);
spin_unlock_bh(&tt->lock);
}

Expand Down Expand Up @@ -253,7 +261,7 @@ tt_transmit(struct sk_buff *skb, struct net_device *dev)
return NETDEV_TX_OK;
}

printk(KERN_DEBUG "TashTalk: send data on %s\n", dev->name);
if (tash_debug) printk(KERN_DEBUG "TashTalk: send data on %s\n", dev->name);

spin_lock(&tt->lock);
if (!netif_running(dev)) {
Expand Down Expand Up @@ -355,7 +363,7 @@ unsigned char tt_arbitrate_addr_blocking(struct tashtalk *tt, unsigned char addr
max = 254;
}

printk(KERN_DEBUG "TashTalk: start address arbitration, requested %i", addr);
if (tash_debug) printk(KERN_DEBUG "TashTalk: start address arbitration, requested %i", addr);

set_bit(TT_FLAG_WAITADDR, &tt->flags);

Expand All @@ -370,57 +378,57 @@ unsigned char tt_arbitrate_addr_blocking(struct tashtalk *tt, unsigned char addr

get_random_bytes(&rand, 1);
newaddr = min + rand % (max - min + 1);
printk(KERN_DEBUG "TashTalk: addr %i is in use, try %i", addr, newaddr);
if (tash_debug) printk(KERN_DEBUG "TashTalk: addr %i is in use, try %i", addr, newaddr);
addr = newaddr;
}
}

clear_bit(TT_FLAG_WAITADDR, &tt->flags);
clear_bit(TT_FLAG_GOTACK, &tt->flags);

printk(KERN_DEBUG "TashTalk: arbitrated address is %i", addr);
if (tash_debug)
printk(KERN_DEBUG "TashTalk: arbitrated address is %i", addr);

return addr;
}

static int tt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{
struct tashtalk *tt = netdev_priv(dev);
struct sockaddr_at *sa = (struct sockaddr_at *)&ifr->ifr_addr;
struct atalk_addr *aa = &tt->node_addr;

switch(cmd)
{
case SIOCSIFADDR:
struct tashtalk *tt = netdev_priv(dev);
struct sockaddr_at *sa = (struct sockaddr_at *)&ifr->ifr_addr;
struct atalk_addr *aa = &tt->node_addr;

sa->sat_addr.s_node = tt_arbitrate_addr_blocking(tt, sa->sat_addr.s_node);
switch(cmd)
{
case SIOCSIFADDR:

aa->s_net = sa->sat_addr.s_net;
aa->s_node = sa->sat_addr.s_node; //FIXME! arbitrate id
sa->sat_addr.s_node = tt_arbitrate_addr_blocking(tt, sa->sat_addr.s_node);

/* Set broardcast address. */
dev->broadcast[0] = 0xFF;

/* Set hardware address. */
dev->addr_len = 1;
dev_addr_set(dev, &aa->s_node);
aa->s_net = sa->sat_addr.s_net;
aa->s_node = sa->sat_addr.s_node;

// Setup tashtalk to respond to that addr
tash_setbits(tt, aa->s_node);
/* Set broardcast address. */
dev->broadcast[0] = 0xFF;

/* Set hardware address. */
dev->addr_len = 1;
dev_addr_set(dev, &aa->s_node);

printk(KERN_DEBUG "TashTalk: set addr to: %i.%i", aa->s_net, aa->s_node);
return 0;
// Setup tashtalk to respond to that addr
tash_setbits(tt, aa->s_node);

if (tash_debug) printk(KERN_DEBUG "TashTalk: set addr to: %i.%i", aa->s_net, aa->s_node);
return 0;

case SIOCGIFADDR:
sa->sat_addr.s_net = aa->s_net;
sa->sat_addr.s_node = aa->s_node;
printk(KERN_DEBUG "TashTalk: read addr: %i.%i", aa->s_net, aa->s_node);
return 0;
case SIOCGIFADDR:
sa->sat_addr.s_net = aa->s_net;
sa->sat_addr.s_node = aa->s_node;
if (tash_debug) printk(KERN_DEBUG "TashTalk: read addr: %i.%i", aa->s_net, aa->s_node);
return 0;

//default:
// return -EOPNOTSUPP;
}
return 0;
default:
return -EOPNOTSUPP;
}
}

/* The destructor */
Expand All @@ -434,7 +442,7 @@ static void tt_free_netdev(struct net_device *dev)
/* Copied from cops.c, make appletalk happy */
static void tt_set_multicast(struct net_device *dev)
{
printk(KERN_DEBUG "TashTalk: %s set_multicast_list executed\n", dev->name);
printk(KERN_INFO "TashTalk: %s set_multicast_list executed\n", dev->name);
}

static const struct net_device_ops tt_netdev_ops = {
Expand Down Expand Up @@ -475,7 +483,7 @@ static void tashtalk_manage_control_frame(struct tashtalk *tt) {
case LLAP_ENQ:

if ( tt->node_addr.s_node != 0 && tt->rbuff[LLAP_SRC_POS] == tt->node_addr.s_node) {
printk(KERN_DEBUG "TashTalk: repply ACK to ENQ from %i", tt->rbuff[LLAP_SRC_POS]);
if (tash_debug) printk(KERN_DEBUG "TashTalk: repply ACK to ENQ from %i", tt->rbuff[LLAP_SRC_POS]);
//tashtalk_send_ack(tt, tt->rbuff[LLAP_SRC_POS]);
tashtalk_send_ctrl_packet(tt, tt->rbuff[LLAP_SRC_POS], tt->node_addr.s_node, LLAP_ACK);
}
Expand All @@ -497,7 +505,7 @@ static int tashtalk_is_control_frame(unsigned char *frame) {
}

static void tashtalk_manage_valid_frame(struct tashtalk *tt) {
printk(KERN_DEBUG "(3) TashTalk done frame, len=%i", tt->rcount);
if (tash_debug) printk(KERN_DEBUG "(3) TashTalk done frame, len=%i", tt->rcount);
// echo 'file tashtalk.c line 403 +p' > /sys/kernel/debug/dynamic_debug/control
print_hex_dump_bytes("(3a) LLAP IN frame: ", DUMP_PREFIX_NONE, tt->rbuff, tt->rcount);

Expand All @@ -507,7 +515,7 @@ static void tashtalk_manage_valid_frame(struct tashtalk *tt) {
else
tt_post_to_netif(tt);

printk(KERN_DEBUG "(4) TashTalk next frame");
if (tash_debug) printk(KERN_DEBUG "(4) TashTalk next frame");
}

static void tashtalk_manage_escape(struct tashtalk *tt, unsigned char seq)
Expand Down Expand Up @@ -538,15 +546,15 @@ static void tashtalk_receive_buf(struct tty_struct *tty, const unsigned char *cp
if (!tt || tt->magic != TASH_MAGIC || !netif_running(tt->dev))
return;

printk(KERN_DEBUG "(1) TashTalk read %i", count);
if (tash_debug) printk(KERN_DEBUG "(1) TashTalk read %i", count);
print_hex_dump_bytes("Tash read: ", DUMP_PREFIX_NONE, cp, count);

// Fresh frame
if (!test_bit(TT_FLAG_INFRAME, &tt->flags)) {
tt->rcount = 0;
printk(KERN_DEBUG "(2) TashTalk start new frame");
if (tash_debug) printk(KERN_DEBUG "(2) TashTalk start new frame");
} else
printk(KERN_DEBUG "(2) TashTalk continue frame");
if (tash_debug) printk(KERN_DEBUG "(2) TashTalk continue frame");

set_bit(TT_FLAG_INFRAME, &tt->flags);

Expand All @@ -573,7 +581,7 @@ static void tashtalk_receive_buf(struct tty_struct *tty, const unsigned char *cp

}

printk(KERN_DEBUG "(5) Done read, pending frame=%i", test_bit(TT_FLAG_INFRAME, &tt->flags));
if (tash_debug) printk(KERN_DEBUG "(5) Done read, pending frame=%i", test_bit(TT_FLAG_INFRAME, &tt->flags));
}

/* Free a channel buffers. */
Expand Down Expand Up @@ -848,7 +856,7 @@ static int tashtalk_ioctl(struct tty_struct *tty, unsigned int cmd,

static struct tty_ldisc_ops tashtalk_ldisc = {
.owner = THIS_MODULE,
.num = N_PPP,//N_SLIP,
.num = 29, // this is the official one for testing
.name = "tasktalk",
.open = tashtalk_open,
.close = tashtalk_close,
Expand Down

0 comments on commit a459fa0

Please sign in to comment.