This repository contains a modified version of **OSCam** enhanced with an advanced **AI-inspired Fake DCW Detection and Voting System**.
The goal of this system is to improve stability and reliability when multiple Control Word (CW) sources are available, such as:
- Local readers
- CacheEx peers
- CSP sources
- Virtual readers
Instead of accepting the first CW received, this implementation collects multiple candidates and selects the most reliable one using weighted voting logic.
---
# 🔍 Problem It Solves
In multi-reader or CacheEx environments, fake or unstable DCWs can appear.
Default behavior:
- First CW wins
- Possible glitches, freezing, or unstable decoding
With AI Fake DCW Detector:
- Multiple CWs are collected
- Sources are tracked
- Votes are counted
- Local readers can be weighted higher
- Majority or timeout logic is applied
- A reliable CW is selected
Result:
✔ Reduced fake DCWs
✔ Increased decoding stability
✔ Better CacheEx reliability
✔ Smarter CW selection
---
# 🧠 Core Functions
## 1️⃣ `cw_vote_add()`
This function is called whenever a new CW is received.
It:
- Compares the CW with existing candidates
- Increases vote count if it matches
- Adds a new candidate if it is unique
- Tracks:
- Total votes
- Local votes
- Reader source
- CW value
- Identifies whether the source is:
- Local reader
- Virtual reader
- CacheEx client
- CSP source
Each CW candidate is stored in a voting pool.
---
## 2️⃣ `cw_vote_decide()`
This function determines the final CW to use.
### Decision Process
1. Count total votes
2. Verify minimum vote requirement
3. Calculate effective score:
4. Check for majority (> 50%)
5. Apply timeout logic
6. Apply fallback strategy if necessary
If a winner is found:
- CW is copied into `er->cw`
- CacheEx hit statistics are updated
- Optional logging is performed
If no clear winner exists, the system waits for more votes unless timeout rules apply.
---
# ⚙ Configuration Options
| Parameter | Description |
|------------|------------|
| `cwvote_enabled` | Enable/disable voting system |
| `cwvote_max_candidates` | Maximum CW candidates stored |
| `cwvote_compare_len` | Number of bytes used for CW comparison |
| `cwvote_local_weight` | Weight multiplier for local votes |
| `cwvote_min_votes` | Minimum required votes before decision |
| `cwvote_timeout` | Timeout in milliseconds |
| `cwvote_fallback` | Fallback mode (1 = best candidate, 2 = first candidate) |