Browse Source

data/code-gen: add support for indications

Indication (or also notifactions) are send by the modem towards the hosts.
They are similar to response, but without a request.
Some indication will send towards the host as soon the host has created a
session with a service. For other indication the host need to subscribe first.

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
Alexander Couzens 1 month ago
parent
commit
7c77e7742e
3 changed files with 83 additions and 3 deletions
  1. 67 1
      data/gen-code.pl
  2. 14 0
      data/gen-common.pm
  3. 2 2
      data/gen-header.pl

+ 67 - 1
data/gen-code.pl

@@ -251,6 +251,72 @@ EOF
 EOF
 }
 
+sub gen_parse_ind_func($$)
+{
+	my $name = shift;
+	my $data = shift;
+
+	my $type = "svc";
+	$ctl and $type = "ctl";
+
+	print gen_tlv_parse_func($name, $data)."\n";
+	print <<EOF;
+{
+	void *tlv_buf = &msg->$type.tlv;
+	unsigned int tlv_len = le16_to_cpu(msg->$type.tlv_len);
+EOF
+
+	if (gen_has_types($data)) {
+		my $n_bits = scalar @$data;
+		my $n_words = int(($n_bits + 31) / 32);
+		my $i = 0;
+
+		print <<EOF;
+	struct tlv *tlv;
+	int i;
+	uint32_t found[$n_words] = {};
+
+	memset(res, 0, sizeof(*res));
+
+	__qmi_alloc_reset();
+	while ((tlv = tlv_get_next(&tlv_buf, &tlv_len)) != NULL) {
+		unsigned int cur_tlv_len = le16_to_cpu(tlv->len);
+		unsigned int ofs = 0;
+
+		switch(tlv->type) {
+EOF
+		foreach my $field (@$data) {
+			$field = gen_common_ref($field);
+			my $cname = gen_cname($field->{name});
+			gen_tlv_type($cname, $field, $i++);
+		}
+
+		print <<EOF;
+		default:
+			break;
+		}
+	}
+
+	return 0;
+
+error_len:
+	fprintf(stderr, "%s: Invalid TLV length in message, tlv=0x%02x, len=%d\\n",
+	        __func__, tlv->type, le16_to_cpu(tlv->len));
+	return QMI_ERROR_INVALID_DATA;
+EOF
+	} else {
+		print <<EOF;
+
+	return qmi_check_message_status(tlv_buf, tlv_len);
+EOF
+	}
+
+	print <<EOF;
+}
+
+EOF
+}
+
 my %tlv_set = (
 	guint8 => sub { my $a = shift; my $b = shift; print "*(uint8_t *) $a = $b;\n" },
 	guint16 => sub { my $a = shift; my $b = shift; print "*(uint16_t *) $a = cpu_to_le16($b);\n" },
@@ -454,4 +520,4 @@ print <<EOF;
 
 EOF
 
-gen_foreach_message_type($data, \&gen_set_func, \&gen_parse_func);
+gen_foreach_message_type($data, \&gen_set_func, \&gen_parse_func, \&gen_parse_ind_func);

+ 14 - 0
data/gen-common.pm

@@ -82,6 +82,7 @@ sub gen_foreach_message_type($$$)
 	my $data = shift;
 	my $req_sub = shift;
 	my $res_sub = shift;
+	my $ind_sub = shift;
 
 	foreach my $entry (@$data) {
 		my $args = [];
@@ -95,6 +96,19 @@ sub gen_foreach_message_type($$$)
 		&$req_sub($prefix.$entry->{name}." Request", $entry->{input}, $entry);
 		&$res_sub($prefix.$entry->{name}." Response", $entry->{output}, $entry);
 	}
+
+	foreach my $entry (@$data) {
+		my $args = [];
+		my $fields = [];
+
+		$common_ref{$entry->{'common-ref'}} = $entry if $entry->{'common-ref'} ne '';
+
+		next if $entry->{type} ne 'Indication';
+		next if not defined $entry->{input} and not defined $entry->{output};
+
+		&$ind_sub($prefix.$entry->{name}." Indication", $entry->{output}, $entry);
+	}
 }
 
+
 1;

+ 2 - 2
data/gen-header.pl

@@ -115,5 +115,5 @@ sub gen_parse_func_header($$)
 	$func and print "$func;\n\n";
 }
 
-gen_foreach_message_type($data, \&gen_tlv_struct, \&gen_tlv_struct);
-gen_foreach_message_type($data, \&gen_set_func_header, \&gen_parse_func_header);
+gen_foreach_message_type($data, \&gen_tlv_struct, \&gen_tlv_struct, \&gen_tlv_struct);
+gen_foreach_message_type($data, \&gen_set_func_header, \&gen_parse_func_header, \&gen_parse_func_header);