Browse Source

Simplify get_cw() protocol call.

Handle errors in generic camd code instead of protocol code.
Georgi Chorbadzhiyski 12 years ago
parent
commit
ce5db9e050
2 changed files with 19 additions and 16 deletions
  1. 3
    12
      camd-cs378x.c
  2. 16
    4
      camd.c

+ 3
- 12
camd-cs378x.c View File

@@ -135,11 +135,8 @@ static int cs378x_get_cw(struct camd *c, uint16_t *ca_id, uint16_t *idx, uint8_t
135 135
 
136 136
 READ:
137 137
 	ret = cs378x_recv(c, data, &data_len);
138
-	if (ret < 0) {
139
-		ts_LOGf("ERR | No code word has been received (ret = %d)\n", ret);
140
-		cs378x_reconnect(c);
141
-		return ret;
142
-	}
138
+	if (ret < 0) // Fatal error
139
+		return -1;
143 140
 
144 141
 	// EMM request, ignore it. Sometimes OSCAM sends two EMM requests after CW
145 142
 	if (data[0] == 0x05)
@@ -150,12 +147,6 @@ READ:
150 147
 			data[0],
151 148
 			data[0] == 0x08 ? "No card" :
152 149
 			data[0] == 0x44 ? "No code word found" : "Unknown err");
153
-		c->ecm_recv_errors++;
154
-		usleep(10000);
155
-		if (c->ecm_recv_errors >= ECM_RECV_ERRORS_LIMIT) {
156
-			c->key->is_valid_cw = 0;
157
-			memset(cw, 0, 16); // Invalid CW
158
-		}
159 150
 		return 0;
160 151
 	}
161 152
 
@@ -173,7 +164,7 @@ READ:
173 164
 	*idx   = (data[16] << 8) | data[17];
174 165
 	memcpy(cw, data + 20, 16);
175 166
 
176
-	return ret;
167
+	return 1;
177 168
 }
178 169
 
179 170
 void camd_proto_cs378x(struct camd_ops *ops) {

+ 16
- 4
camd.c View File

@@ -70,10 +70,22 @@ static int camd_recv_cw(struct ts *ts) {
70 70
 
71 71
 	gettimeofday(&tv1, NULL);
72 72
 	ret = c->ops.get_cw(c, &ca_id, &idx, c->key->cw);
73
-	if (ret <= 0)
74
-		return ret;
75 73
 	gettimeofday(&tv2, NULL);
76 74
 
75
+	if (ret <= 0) {
76
+		if (ret == -1) { // Fatal error it is better to reconnect to server.
77
+			ts_LOGf("ERR | No code word has been received (ret = %d)\n", ret);
78
+			c->ops.reconnect(c);
79
+		}
80
+		c->ecm_recv_errors++;
81
+		if (c->ecm_recv_errors >= ECM_RECV_ERRORS_LIMIT) {
82
+			c->key->is_valid_cw = 0;
83
+			memset(c->key->cw, 0, 16); // Invalid CW
84
+		}
85
+		usleep(10000);
86
+		return 0;
87
+	}
88
+
77 89
 	char cw_dump[16 * 6];
78 90
 	ts_hex_dump_buf(cw_dump, 16 * 6, c->key->cw, 16, 0);
79 91
 
@@ -110,7 +122,7 @@ static int camd_recv_cw(struct ts *ts) {
110 122
 			idx, cw_dump );
111 123
 	}
112 124
 
113
-	return ret;
125
+	return 1;
114 126
 }
115 127
 
116 128
 #undef ERR
@@ -126,7 +138,7 @@ static int camd_send_ecm(struct ts *ts, struct camd_msg *msg) {
126 138
 	}
127 139
 
128 140
 	ret = camd_recv_cw(ts);
129
-	if (ret < 48) {
141
+	if (ret < 1) {
130 142
 		ts->is_cw_error = 1;
131 143
 		if (ts->key.ts && time(NULL) - ts->key.ts > KEY_VALID_TIME) {
132 144
 			if (c->key->is_valid_cw)

Loading…
Cancel
Save